]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/peripherals/pio.h
Add SAMA5D2 Xplained IAR demo.
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / AtmelFiles / drivers / peripherals / pio.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 #ifndef _PIO_H\r
31 #define _PIO_H\r
32 \r
33 #define IRQ_PIO_HANDLERS_SIZE 16\r
34 \r
35 /*------------------------------------------------------------------------------\r
36  *         Global Types\r
37  *------------------------------------------------------------------------------*/\r
38 \r
39 #include "chip.h"\r
40 \r
41 struct _pin\r
42 {\r
43         uint8_t group;      /*< The IO group containing the pins you want to use. */\r
44         uint32_t mask;      /*< Bitmask indicating which pin(s) to configure. */\r
45         uint8_t type;       /*< Pin type */\r
46         uint32_t attribute; /*< Pin config attribute. */\r
47 };\r
48 \r
49 typedef void(*pio_handler_t)(uint32_t, uint32_t, void*);\r
50 \r
51 /*------------------------------------------------------------------------------\r
52  *         Headers\r
53  *------------------------------------------------------------------------------*/\r
54 \r
55 #if defined(CONFIG_HAVE_PIO4)\r
56 #include "peripherals/pio4.h"\r
57 #endif\r
58 \r
59 #ifdef __cplusplus\r
60 extern "C" {\r
61 #endif\r
62 \r
63 /*------------------------------------------------------------------------------\r
64  *         Exported functions\r
65  *------------------------------------------------------------------------------*/\r
66 \r
67 /**\r
68  * \brief Configures a list of Pin instances.\r
69  *\r
70  * \details Each of them can either hold a single pin or a group of\r
71  * pins, depending on the mask value; all pins are configured by this\r
72  * function. The size of the array must also be provided and is easily\r
73  * computed using ARRAY_SIZE whenever its length is not known in\r
74  * advance.\r
75  *\r
76  * \param list  Pointer to a list of Pin instances.\r
77  * \param size  Size of the Pin list (calculated using ARRAY_SIZE).\r
78  *\r
79  * \return 1 if the pins have been configured properly; otherwise 0.\r
80  */\r
81 extern uint8_t pio_configure(const struct _pin *list, uint32_t size);\r
82 \r
83 /**\r
84  * \brief Sets a high output level on all the PIOs defined in the\r
85  * given Pin instance.\r
86  *\r
87  * \details This has no immediate effects on PIOs that are not output,\r
88  * but the PIO controller will memorize the value they are changed to\r
89  * outputs.\r
90  *\r
91  * \param pin  Pointer to a Pin instance describing one or more pins.\r
92  */\r
93 extern void pio_set(const struct _pin *pin);\r
94 \r
95 /**\r
96  * \brief Sets a low output level on all the PIOs defined in the given\r
97  * Pin instance.\r
98  *\r
99  * \details This has no immediate effects on PIOs that are not output,\r
100  * but the PIO controller will memorize the value they are changed to\r
101  * outputs.\r
102  *\r
103  * \param pin  Pointer to a Pin instance describing one or more pins.\r
104  */\r
105 extern void pio_clear(const struct _pin *pin);\r
106 \r
107 /**\r
108  * \brief Returns 1 if one or more PIO of the given Pin instance currently have\r
109  * a high level; otherwise returns 0. This method returns the actual value that\r
110  * is being read on the pin. To return the supposed output value of a pin, use\r
111  * \ref pio_get_output_date_status() instead.\r
112  *\r
113  * \param pin  Pointer to a Pin instance describing one or more pins.\r
114  *\r
115  * \return 1 if the Pin instance contains at least one PIO that currently has\r
116  * a high level; otherwise 0.\r
117  */\r
118 extern uint8_t pio_get(const struct _pin *pin);\r
119 \r
120 /**\r
121  * \brief Returns 1 if one or more PIO of the given Pin are configured to output a\r
122  * high level (even if they are not output).\r
123  * To get the actual value of the pin, use pio_get() instead.\r
124  *\r
125  * \param pin  Pointer to a Pin instance describing one or more pins.\r
126  *\r
127  * \return 1 if the Pin instance contains at least one PIO that is configured\r
128  * to output a high level; otherwise 0.\r
129  */\r
130 extern uint8_t pio_get_output_data_status(const struct _pin *pin);\r
131 \r
132 /**\r
133  * \brief Configures Glitch or Debouncing filter for input.\r
134  *\r
135  * \param pin  Pointer to a Pin instance describing one or more pins.\r
136  * \param cuttoff  Cutt off frequency for debounce filter.\r
137  */\r
138 extern void pio_set_debounce_filter(const struct _pin *pin, uint32_t cuttoff);\r
139 \r
140 /**\r
141  * \brief Enable write protect.\r
142  *\r
143  * \param pin  Pointer to a Pin instance describing one or more pins.\r
144  */\r
145 extern void pio_enable_write_protect(const struct _pin *pin);\r
146 \r
147 /**\r
148  * \brief Disable write protect.\r
149  *\r
150  * \param pin  Pointer to a Pin instance describing one or more pins.\r
151  */\r
152 extern void pio_disable_write_protect(const struct _pin *pin);\r
153 \r
154 /**\r
155  * \brief Get write protect violation information.\r
156  *\r
157  * \param pin  Pointer to a Pin instance describing one or more pins.\r
158  */\r
159 extern uint32_t pio_get_write_protect_violation_info(const struct _pin * pin);\r
160 \r
161 /**\r
162  * \brief Configure all pio outputs low\r
163  *\r
164  * \param group PIO group number\r
165  * \param mask  Bitmask of one or more pin(s) to configure.\r
166  */\r
167 extern void pio_output_low(uint32_t group, uint32_t mask);\r
168 \r
169 extern void pio_add_handler_to_group(uint32_t group, uint32_t mask,\r
170                                      pio_handler_t handler, void* user_arg);\r
171 \r
172 extern void pio_reset_all_it(void);\r
173 \r
174 /**\r
175  * \brief Generate an interrupt on status change for a PIO or a group\r
176  * of PIO.\r
177 \r
178  * \details The provided interrupt handler will be called with the\r
179  * triggering pin as its parameter (enabling different pin instances\r
180  * to share the same handler).\r
181  *\r
182  * \param pin  Pointer to a _pin instance.\r
183  */\r
184 extern void pio_configure_it(const struct _pin * pin);\r
185 \r
186 \r
187 /**\r
188  * Enables the given interrupt source if it has been configured. The status\r
189  * register of the corresponding PIO controller is cleared prior to enabling\r
190  * the interrupt.\r
191  * \param pin  Interrupt source to enable.\r
192  */\r
193 extern void pio_enable_it(const struct _pin * pin);\r
194 \r
195 /**\r
196  * Disables a given interrupt source, with no added side effects.\r
197  *\r
198  * \param pin  Interrupt source to disable.\r
199  */\r
200 extern void pio_disable_it(const struct _pin * pin);\r
201 \r
202 #ifdef __cplusplus\r
203 }\r
204 #endif\r
205 #endif /* _PIO_H */\r