usart_serial.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * \brief Send a sequence of bytes to USART device
  51. *
  52. * \param usart Base address of the USART instance.
  53. * \param data Data buffer to read
  54. * \param len Length of data
  55. *
  56. */
  57. status_code_t usart_serial_write_packet(usart_if usart, const uint8_t *data,
  58. size_t len)
  59. {
  60. while (len) {
  61. usart_serial_putchar(usart, *data);
  62. len--;
  63. data++;
  64. }
  65. return STATUS_OK;
  66. }
  67. /**
  68. * \brief Receive a sequence of bytes from USART device
  69. *
  70. * \param usart Base address of the USART instance.
  71. * \param data Data buffer to write
  72. * \param len Length of data
  73. *
  74. */
  75. status_code_t usart_serial_read_packet(usart_if usart, uint8_t *data,
  76. size_t len)
  77. {
  78. while (len) {
  79. usart_serial_getchar(usart, data);
  80. len--;
  81. data++;
  82. }
  83. return STATUS_OK;
  84. }