1 /**
2 *
3 * \file
4 *
5 * \brief USART Serial driver functions.
6 *
7 *
8 * Copyright (c) 2010-2015 Atmel Corporation. All rights reserved.
9 *
10 * \asf_license_start
11 *
12 * \page License
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are met:
16 *
17 * 1. Redistributions of source code must retain the above copyright notice,
18 * this list of conditions and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above copyright notice,
21 * this list of conditions and the following disclaimer in the documentation
22 * and/or other materials provided with the distribution.
23 *
24 * 3. The name of Atmel may not be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * 4. This software may only be redistributed and used in connection with an
28 * Atmel microcontroller product.
29 *
30 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
31 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
33 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
34 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
38 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
39 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
41 *
42 * \asf_license_stop
43 *
44 */
45 /*
46 * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
47 */
48 #include "serial.h"
49
50 /**
51 * \brief Send a sequence of bytes to USART device
52 *
53 * \param usart Base address of the USART instance.
54 * \param data Data buffer to read
55 * \param len Length of data
56 *
57 */
usart_serial_write_packet(usart_if usart,const uint8_t * data,size_t len)58 status_code_t usart_serial_write_packet(usart_if usart, const uint8_t *data,
59 size_t len)
60 {
61 while (len) {
62 usart_serial_putchar(usart, *data);
63 len--;
64 data++;
65 }
66 return STATUS_OK;
67 }
68
69
70 /**
71 * \brief Receive a sequence of bytes from USART device
72 *
73 * \param usart Base address of the USART instance.
74 * \param data Data buffer to write
75 * \param len Length of data
76 *
77 */
usart_serial_read_packet(usart_if usart,uint8_t * data,size_t len)78 status_code_t usart_serial_read_packet(usart_if usart, uint8_t *data,
79 size_t len)
80 {
81 while (len) {
82 usart_serial_getchar(usart, data);
83 len--;
84 data++;
85 }
86 return STATUS_OK;
87 }
88