1 /**
2  * \file
3  *
4  * \brief SAM SERCOM USART Asynchronous Driver
5  *
6  * Copyright (C) 2012-2015 Atmel Corporation. All rights reserved.
7  *
8  * \asf_license_start
9  *
10  * \page License
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright notice,
16  *    this list of conditions and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright notice,
19  *    this list of conditions and the following disclaimer in the documentation
20  *    and/or other materials provided with the distribution.
21  *
22  * 3. The name of Atmel may not be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * 4. This software may only be redistributed and used in connection with an
26  *    Atmel microcontroller product.
27  *
28  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
29  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
31  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
32  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  *
40  * \asf_license_stop
41  *
42  */
43 /*
44  * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
45  */
46 #ifndef USART_INTERRUPT_H_INCLUDED
47 #define USART_INTERRUPT_H_INCLUDED
48 
49 #include "usart.h"
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 #if !defined(__DOXYGEN__)
56 enum status_code _usart_write_buffer(
57 		struct usart_module *const module,
58 		uint8_t *tx_data,
59 		uint16_t length);
60 
61 enum status_code _usart_read_buffer(
62 		struct usart_module *const module,
63 		uint8_t *rx_data,
64 		uint16_t length);
65 
66 void _usart_interrupt_handler(
67 		uint8_t instance);
68 #endif
69 
70 /**
71  * \addtogroup asfdoc_sam0_sercom_usart_group
72  *
73  * @{
74  */
75 
76 /**
77  * \name Callback Management
78  * @{
79  */
80 void usart_register_callback(
81 		struct usart_module *const module,
82 		usart_callback_t callback_func,
83 		enum usart_callback callback_type);
84 
85 void usart_unregister_callback(
86 		struct usart_module *module,
87 		enum usart_callback callback_type);
88 
89 /**
90  * \brief Enables callback
91  *
92  * Enables the callback function registered by the \ref usart_register_callback.
93  * The callback function will be called from the interrupt handler when the
94  * conditions for the callback type are met.
95  *
96  * \param[in]  module         Pointer to USART software instance struct
97  * \param[in]  callback_type  Callback type given by an enum
98  */
usart_enable_callback(struct usart_module * const module,enum usart_callback callback_type)99 static inline void usart_enable_callback(
100 		struct usart_module *const module,
101 		enum usart_callback callback_type)
102 {
103 	/* Sanity check arguments */
104 	Assert(module);
105 
106 	/* Enable callback */
107 	module->callback_enable_mask |= (1 << callback_type);
108 
109 }
110 
111 /**
112  * \brief Disable callback
113  *
114  * Disables the callback function registered by the \ref usart_register_callback,
115  * and the callback will not be called from the interrupt routine.
116  *
117  * \param[in]  module         Pointer to USART software instance struct
118  * \param[in]  callback_type  Callback type given by an enum
119  */
usart_disable_callback(struct usart_module * const module,enum usart_callback callback_type)120 static inline void usart_disable_callback(
121 		struct usart_module *const module,
122 		enum usart_callback callback_type)
123 {
124 	/* Sanity check arguments */
125 	Assert(module);
126 
127 	/* Disable callback */
128 	module->callback_enable_mask &= ~(1 << callback_type);
129 }
130 
131 /**
132  * @}
133  */
134 
135 /**
136  * \name Writing and Reading
137  * @{
138  */
139 enum status_code usart_write_job(
140 		struct usart_module *const module,
141 		const uint16_t *tx_data);
142 
143 enum status_code usart_read_job(
144 		struct usart_module *const module,
145 		uint16_t *const rx_data);
146 
147 enum status_code usart_write_buffer_job(
148 		struct usart_module *const module,
149 		uint8_t *tx_data,
150 		uint16_t length);
151 
152 enum status_code usart_read_buffer_job(
153 		struct usart_module *const module,
154 		uint8_t *rx_data,
155 		uint16_t length);
156 
157 void usart_abort_job(
158 		struct usart_module *const module,
159 		enum usart_transceiver_type transceiver_type);
160 
161 enum status_code usart_get_job_status(
162 		struct usart_module *const module,
163 		enum usart_transceiver_type transceiver_type);
164 /**
165  * @}
166  */
167 
168 /**
169  * @}
170  */
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif /* USART_INTERRUPT_H_INCLUDED */
177 
178