Mouse code for the MacroRat
mbed-dev/targets/TARGET_Atmel/TARGET_SAM_CortexM4/services/serial/serial_platform.h@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * \file |
sahilmgandhi | 18:6a4db94011d3 | 3 | * |
sahilmgandhi | 18:6a4db94011d3 | 4 | * \brief Serial Mode management |
sahilmgandhi | 18:6a4db94011d3 | 5 | * |
sahilmgandhi | 18:6a4db94011d3 | 6 | * Copyright (c) 2010-2015 Atmel Corporation. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * \asf_license_start |
sahilmgandhi | 18:6a4db94011d3 | 9 | * |
sahilmgandhi | 18:6a4db94011d3 | 10 | * \page License |
sahilmgandhi | 18:6a4db94011d3 | 11 | * |
sahilmgandhi | 18:6a4db94011d3 | 12 | * Redistribution and use in source and binary forms, with or without |
sahilmgandhi | 18:6a4db94011d3 | 13 | * modification, are permitted provided that the following conditions are met: |
sahilmgandhi | 18:6a4db94011d3 | 14 | * |
sahilmgandhi | 18:6a4db94011d3 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 16 | * this list of conditions and the following disclaimer. |
sahilmgandhi | 18:6a4db94011d3 | 17 | * |
sahilmgandhi | 18:6a4db94011d3 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 19 | * this list of conditions and the following disclaimer in the documentation |
sahilmgandhi | 18:6a4db94011d3 | 20 | * and/or other materials provided with the distribution. |
sahilmgandhi | 18:6a4db94011d3 | 21 | * |
sahilmgandhi | 18:6a4db94011d3 | 22 | * 3. The name of Atmel may not be used to endorse or promote products derived |
sahilmgandhi | 18:6a4db94011d3 | 23 | * from this software without specific prior written permission. |
sahilmgandhi | 18:6a4db94011d3 | 24 | * |
sahilmgandhi | 18:6a4db94011d3 | 25 | * 4. This software may only be redistributed and used in connection with an |
sahilmgandhi | 18:6a4db94011d3 | 26 | * Atmel microcontroller product. |
sahilmgandhi | 18:6a4db94011d3 | 27 | * |
sahilmgandhi | 18:6a4db94011d3 | 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED |
sahilmgandhi | 18:6a4db94011d3 | 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
sahilmgandhi | 18:6a4db94011d3 | 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
sahilmgandhi | 18:6a4db94011d3 | 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR |
sahilmgandhi | 18:6a4db94011d3 | 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
sahilmgandhi | 18:6a4db94011d3 | 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
sahilmgandhi | 18:6a4db94011d3 | 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
sahilmgandhi | 18:6a4db94011d3 | 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
sahilmgandhi | 18:6a4db94011d3 | 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
sahilmgandhi | 18:6a4db94011d3 | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
sahilmgandhi | 18:6a4db94011d3 | 38 | * POSSIBILITY OF SUCH DAMAGE. |
sahilmgandhi | 18:6a4db94011d3 | 39 | * |
sahilmgandhi | 18:6a4db94011d3 | 40 | * \asf_license_stop |
sahilmgandhi | 18:6a4db94011d3 | 41 | * |
sahilmgandhi | 18:6a4db94011d3 | 42 | */ |
sahilmgandhi | 18:6a4db94011d3 | 43 | /* |
sahilmgandhi | 18:6a4db94011d3 | 44 | * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> |
sahilmgandhi | 18:6a4db94011d3 | 45 | */ |
sahilmgandhi | 18:6a4db94011d3 | 46 | #ifndef SERIAL_PLATFORM_H_INCLUDED |
sahilmgandhi | 18:6a4db94011d3 | 47 | #define SERIAL_PLATFORM_H_INCLUDED |
sahilmgandhi | 18:6a4db94011d3 | 48 | |
sahilmgandhi | 18:6a4db94011d3 | 49 | #include <parts.h> |
sahilmgandhi | 18:6a4db94011d3 | 50 | #include "status_codes.h" |
sahilmgandhi | 18:6a4db94011d3 | 51 | |
sahilmgandhi | 18:6a4db94011d3 | 52 | /** |
sahilmgandhi | 18:6a4db94011d3 | 53 | * \typedef usart_if |
sahilmgandhi | 18:6a4db94011d3 | 54 | * |
sahilmgandhi | 18:6a4db94011d3 | 55 | * This type can be used independently to refer to USART module for the |
sahilmgandhi | 18:6a4db94011d3 | 56 | * architecture used. It refers to the correct type definition for the |
sahilmgandhi | 18:6a4db94011d3 | 57 | * architecture, ie. USART_t* for XMEGA or avr32_usart_t* for UC3. |
sahilmgandhi | 18:6a4db94011d3 | 58 | */ |
sahilmgandhi | 18:6a4db94011d3 | 59 | |
sahilmgandhi | 18:6a4db94011d3 | 60 | #if XMEGA |
sahilmgandhi | 18:6a4db94011d3 | 61 | # include "xmega_usart/usart_serial.h" |
sahilmgandhi | 18:6a4db94011d3 | 62 | #elif MEGA_RF |
sahilmgandhi | 18:6a4db94011d3 | 63 | # include "megarf_usart/usart_serial.h" |
sahilmgandhi | 18:6a4db94011d3 | 64 | #elif UC3 |
sahilmgandhi | 18:6a4db94011d3 | 65 | # include "uc3_usart/usart_serial.h" |
sahilmgandhi | 18:6a4db94011d3 | 66 | #elif (SAMB) |
sahilmgandhi | 18:6a4db94011d3 | 67 | #include "samb_uart/uart_serial.h" |
sahilmgandhi | 18:6a4db94011d3 | 68 | #elif (SAM0) |
sahilmgandhi | 18:6a4db94011d3 | 69 | #include "sam0_usart/usart_serial.h" |
sahilmgandhi | 18:6a4db94011d3 | 70 | #elif SAM |
sahilmgandhi | 18:6a4db94011d3 | 71 | # include "sam_uart/uart_serial.h" |
sahilmgandhi | 18:6a4db94011d3 | 72 | #else |
sahilmgandhi | 18:6a4db94011d3 | 73 | # error Unsupported chip type |
sahilmgandhi | 18:6a4db94011d3 | 74 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 75 | |
sahilmgandhi | 18:6a4db94011d3 | 76 | /** |
sahilmgandhi | 18:6a4db94011d3 | 77 | * |
sahilmgandhi | 18:6a4db94011d3 | 78 | * \defgroup serial_group Serial Interface (Serial) |
sahilmgandhi | 18:6a4db94011d3 | 79 | * |
sahilmgandhi | 18:6a4db94011d3 | 80 | * See \ref serial_quickstart. |
sahilmgandhi | 18:6a4db94011d3 | 81 | * |
sahilmgandhi | 18:6a4db94011d3 | 82 | * This is the common API for serial interface. Additional features are available |
sahilmgandhi | 18:6a4db94011d3 | 83 | * in the documentation of the specific modules. |
sahilmgandhi | 18:6a4db94011d3 | 84 | * |
sahilmgandhi | 18:6a4db94011d3 | 85 | * \section serial_group_platform Platform Dependencies |
sahilmgandhi | 18:6a4db94011d3 | 86 | * |
sahilmgandhi | 18:6a4db94011d3 | 87 | * The serial API is partially chip- or platform-specific. While all |
sahilmgandhi | 18:6a4db94011d3 | 88 | * platforms provide mostly the same functionality, there are some |
sahilmgandhi | 18:6a4db94011d3 | 89 | * variations around how different bus types and clock tree structures |
sahilmgandhi | 18:6a4db94011d3 | 90 | * are handled. |
sahilmgandhi | 18:6a4db94011d3 | 91 | * |
sahilmgandhi | 18:6a4db94011d3 | 92 | * The following functions are available on all platforms, but there may |
sahilmgandhi | 18:6a4db94011d3 | 93 | * be variations in the function signature (i.e. parameters) and |
sahilmgandhi | 18:6a4db94011d3 | 94 | * behaviour. These functions are typically called by platform-specific |
sahilmgandhi | 18:6a4db94011d3 | 95 | * parts of drivers, and applications that aren't intended to be |
sahilmgandhi | 18:6a4db94011d3 | 96 | * portable: |
sahilmgandhi | 18:6a4db94011d3 | 97 | * - usart_serial_init() |
sahilmgandhi | 18:6a4db94011d3 | 98 | * - usart_serial_putchar() |
sahilmgandhi | 18:6a4db94011d3 | 99 | * - usart_serial_getchar() |
sahilmgandhi | 18:6a4db94011d3 | 100 | * - usart_serial_write_packet() |
sahilmgandhi | 18:6a4db94011d3 | 101 | * - usart_serial_read_packet() |
sahilmgandhi | 18:6a4db94011d3 | 102 | * |
sahilmgandhi | 18:6a4db94011d3 | 103 | * |
sahilmgandhi | 18:6a4db94011d3 | 104 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 105 | */ |
sahilmgandhi | 18:6a4db94011d3 | 106 | |
sahilmgandhi | 18:6a4db94011d3 | 107 | //! @} |
sahilmgandhi | 18:6a4db94011d3 | 108 | |
sahilmgandhi | 18:6a4db94011d3 | 109 | /** |
sahilmgandhi | 18:6a4db94011d3 | 110 | * \page serial_quickstart Quick start guide for Serial Interface service |
sahilmgandhi | 18:6a4db94011d3 | 111 | * |
sahilmgandhi | 18:6a4db94011d3 | 112 | * This is the quick start guide for the \ref serial_group "Serial Interface module", with |
sahilmgandhi | 18:6a4db94011d3 | 113 | * step-by-step instructions on how to configure and use the serial in a |
sahilmgandhi | 18:6a4db94011d3 | 114 | * selection of use cases. |
sahilmgandhi | 18:6a4db94011d3 | 115 | * |
sahilmgandhi | 18:6a4db94011d3 | 116 | * The use cases contain several code fragments. The code fragments in the |
sahilmgandhi | 18:6a4db94011d3 | 117 | * steps for setup can be copied into a custom initialization function, while |
sahilmgandhi | 18:6a4db94011d3 | 118 | * the steps for usage can be copied into, e.g., the main application function. |
sahilmgandhi | 18:6a4db94011d3 | 119 | * |
sahilmgandhi | 18:6a4db94011d3 | 120 | * \section serial_use_cases Serial use cases |
sahilmgandhi | 18:6a4db94011d3 | 121 | * - \ref serial_basic_use_case |
sahilmgandhi | 18:6a4db94011d3 | 122 | * - \subpage serial_use_case_1 |
sahilmgandhi | 18:6a4db94011d3 | 123 | * |
sahilmgandhi | 18:6a4db94011d3 | 124 | * \section serial_basic_use_case Basic use case - transmit a character |
sahilmgandhi | 18:6a4db94011d3 | 125 | * In this use case, the serial module is configured for: |
sahilmgandhi | 18:6a4db94011d3 | 126 | * - Using USARTD0 |
sahilmgandhi | 18:6a4db94011d3 | 127 | * - Baudrate: 9600 |
sahilmgandhi | 18:6a4db94011d3 | 128 | * - Character length: 8 bit |
sahilmgandhi | 18:6a4db94011d3 | 129 | * - Parity mode: Disabled |
sahilmgandhi | 18:6a4db94011d3 | 130 | * - Stop bit: None |
sahilmgandhi | 18:6a4db94011d3 | 131 | * - RS232 mode |
sahilmgandhi | 18:6a4db94011d3 | 132 | * |
sahilmgandhi | 18:6a4db94011d3 | 133 | * The use case waits for a received character on the configured USART and |
sahilmgandhi | 18:6a4db94011d3 | 134 | * echoes the character back to the same USART. |
sahilmgandhi | 18:6a4db94011d3 | 135 | * |
sahilmgandhi | 18:6a4db94011d3 | 136 | * \section serial_basic_use_case_setup Setup steps |
sahilmgandhi | 18:6a4db94011d3 | 137 | * |
sahilmgandhi | 18:6a4db94011d3 | 138 | * \subsection serial_basic_use_case_setup_prereq Prerequisites |
sahilmgandhi | 18:6a4db94011d3 | 139 | * -# \ref sysclk_group "System Clock Management (sysclk)" |
sahilmgandhi | 18:6a4db94011d3 | 140 | * |
sahilmgandhi | 18:6a4db94011d3 | 141 | * \subsection serial_basic_use_case_setup_code Example code |
sahilmgandhi | 18:6a4db94011d3 | 142 | * The following configuration must be added to the project (typically to a |
sahilmgandhi | 18:6a4db94011d3 | 143 | * conf_uart_serial.h file, but it can also be added to your main application file.) |
sahilmgandhi | 18:6a4db94011d3 | 144 | * |
sahilmgandhi | 18:6a4db94011d3 | 145 | * \note The following takes SAM3X configuration for example, other devices have similar |
sahilmgandhi | 18:6a4db94011d3 | 146 | * configuration, but their parameters may be different, refer to corresponding header files. |
sahilmgandhi | 18:6a4db94011d3 | 147 | * |
sahilmgandhi | 18:6a4db94011d3 | 148 | * \code |
sahilmgandhi | 18:6a4db94011d3 | 149 | #define USART_SERIAL &USARTD0 |
sahilmgandhi | 18:6a4db94011d3 | 150 | #define USART_SERIAL_BAUDRATE 9600 |
sahilmgandhi | 18:6a4db94011d3 | 151 | #define USART_SERIAL_CHAR_LENGTH US_MR_CHRL_8_BIT |
sahilmgandhi | 18:6a4db94011d3 | 152 | #define USART_SERIAL_PARITY US_MR_PAR_NO |
sahilmgandhi | 18:6a4db94011d3 | 153 | #define USART_SERIAL_STOP_BIT false |
sahilmgandhi | 18:6a4db94011d3 | 154 | \endcode |
sahilmgandhi | 18:6a4db94011d3 | 155 | * |
sahilmgandhi | 18:6a4db94011d3 | 156 | * A variable for the received byte must be added: |
sahilmgandhi | 18:6a4db94011d3 | 157 | * \code uint8_t received_byte; \endcode |
sahilmgandhi | 18:6a4db94011d3 | 158 | * |
sahilmgandhi | 18:6a4db94011d3 | 159 | * Add to application initialization: |
sahilmgandhi | 18:6a4db94011d3 | 160 | * \code |
sahilmgandhi | 18:6a4db94011d3 | 161 | sysclk_init(); |
sahilmgandhi | 18:6a4db94011d3 | 162 | |
sahilmgandhi | 18:6a4db94011d3 | 163 | static usart_serial_options_t usart_options = { |
sahilmgandhi | 18:6a4db94011d3 | 164 | .baudrate = USART_SERIAL_BAUDRATE, |
sahilmgandhi | 18:6a4db94011d3 | 165 | .charlength = USART_SERIAL_CHAR_LENGTH, |
sahilmgandhi | 18:6a4db94011d3 | 166 | .paritytype = USART_SERIAL_PARITY, |
sahilmgandhi | 18:6a4db94011d3 | 167 | .stopbits = USART_SERIAL_STOP_BIT |
sahilmgandhi | 18:6a4db94011d3 | 168 | }; |
sahilmgandhi | 18:6a4db94011d3 | 169 | |
sahilmgandhi | 18:6a4db94011d3 | 170 | usart_serial_init(USART_SERIAL, &usart_options); |
sahilmgandhi | 18:6a4db94011d3 | 171 | \endcode |
sahilmgandhi | 18:6a4db94011d3 | 172 | * |
sahilmgandhi | 18:6a4db94011d3 | 173 | * \subsection serial_basic_use_case_setup_flow Workflow |
sahilmgandhi | 18:6a4db94011d3 | 174 | * -# Initialize system clock: |
sahilmgandhi | 18:6a4db94011d3 | 175 | * - \code sysclk_init(); \endcode |
sahilmgandhi | 18:6a4db94011d3 | 176 | * -# Create serial USART options struct: |
sahilmgandhi | 18:6a4db94011d3 | 177 | * - \code |
sahilmgandhi | 18:6a4db94011d3 | 178 | static usart_serial_options_t usart_options = { |
sahilmgandhi | 18:6a4db94011d3 | 179 | .baudrate = USART_SERIAL_BAUDRATE, |
sahilmgandhi | 18:6a4db94011d3 | 180 | .charlength = USART_SERIAL_CHAR_LENGTH, |
sahilmgandhi | 18:6a4db94011d3 | 181 | .paritytype = USART_SERIAL_PARITY, |
sahilmgandhi | 18:6a4db94011d3 | 182 | .stopbits = USART_SERIAL_STOP_BIT |
sahilmgandhi | 18:6a4db94011d3 | 183 | }; |
sahilmgandhi | 18:6a4db94011d3 | 184 | \endcode |
sahilmgandhi | 18:6a4db94011d3 | 185 | * -# Initialize the serial service: |
sahilmgandhi | 18:6a4db94011d3 | 186 | * - \code usart_serial_init(USART_SERIAL, &usart_options);\endcode |
sahilmgandhi | 18:6a4db94011d3 | 187 | * |
sahilmgandhi | 18:6a4db94011d3 | 188 | * \section serial_basic_use_case_usage Usage steps |
sahilmgandhi | 18:6a4db94011d3 | 189 | * |
sahilmgandhi | 18:6a4db94011d3 | 190 | * \subsection serial_basic_use_case_usage_code Example code |
sahilmgandhi | 18:6a4db94011d3 | 191 | * Add to application C-file: |
sahilmgandhi | 18:6a4db94011d3 | 192 | * \code |
sahilmgandhi | 18:6a4db94011d3 | 193 | usart_serial_getchar(USART_SERIAL, &received_byte); |
sahilmgandhi | 18:6a4db94011d3 | 194 | usart_serial_putchar(USART_SERIAL, received_byte); |
sahilmgandhi | 18:6a4db94011d3 | 195 | \endcode |
sahilmgandhi | 18:6a4db94011d3 | 196 | * |
sahilmgandhi | 18:6a4db94011d3 | 197 | * \subsection serial_basic_use_case_usage_flow Workflow |
sahilmgandhi | 18:6a4db94011d3 | 198 | * -# Wait for reception of a character: |
sahilmgandhi | 18:6a4db94011d3 | 199 | * - \code usart_serial_getchar(USART_SERIAL, &received_byte); \endcode |
sahilmgandhi | 18:6a4db94011d3 | 200 | * -# Echo the character back: |
sahilmgandhi | 18:6a4db94011d3 | 201 | * - \code usart_serial_putchar(USART_SERIAL, received_byte); \endcode |
sahilmgandhi | 18:6a4db94011d3 | 202 | */ |
sahilmgandhi | 18:6a4db94011d3 | 203 | |
sahilmgandhi | 18:6a4db94011d3 | 204 | /** |
sahilmgandhi | 18:6a4db94011d3 | 205 | * \page serial_use_case_1 Advanced use case - Send a packet of serial data |
sahilmgandhi | 18:6a4db94011d3 | 206 | * |
sahilmgandhi | 18:6a4db94011d3 | 207 | * In this use case, the USART module is configured for: |
sahilmgandhi | 18:6a4db94011d3 | 208 | * - Using USARTD0 |
sahilmgandhi | 18:6a4db94011d3 | 209 | * - Baudrate: 9600 |
sahilmgandhi | 18:6a4db94011d3 | 210 | * - Character length: 8 bit |
sahilmgandhi | 18:6a4db94011d3 | 211 | * - Parity mode: Disabled |
sahilmgandhi | 18:6a4db94011d3 | 212 | * - Stop bit: None |
sahilmgandhi | 18:6a4db94011d3 | 213 | * - RS232 mode |
sahilmgandhi | 18:6a4db94011d3 | 214 | * |
sahilmgandhi | 18:6a4db94011d3 | 215 | * The use case sends a string of text through the USART. |
sahilmgandhi | 18:6a4db94011d3 | 216 | * |
sahilmgandhi | 18:6a4db94011d3 | 217 | * \section serial_use_case_1_setup Setup steps |
sahilmgandhi | 18:6a4db94011d3 | 218 | * |
sahilmgandhi | 18:6a4db94011d3 | 219 | * \subsection serial_use_case_1_setup_prereq Prerequisites |
sahilmgandhi | 18:6a4db94011d3 | 220 | * -# \ref sysclk_group "System Clock Management (sysclk)" |
sahilmgandhi | 18:6a4db94011d3 | 221 | * |
sahilmgandhi | 18:6a4db94011d3 | 222 | * \subsection serial_use_case_1_setup_code Example code |
sahilmgandhi | 18:6a4db94011d3 | 223 | * The following configuration must be added to the project (typically to a |
sahilmgandhi | 18:6a4db94011d3 | 224 | * conf_uart_serial.h file, but it can also be added to your main application file.): |
sahilmgandhi | 18:6a4db94011d3 | 225 | * |
sahilmgandhi | 18:6a4db94011d3 | 226 | * \note The following takes SAM3X configuration for example, other devices have similar |
sahilmgandhi | 18:6a4db94011d3 | 227 | * configuration, but their parameters may be different, refer to corresponding header files. |
sahilmgandhi | 18:6a4db94011d3 | 228 | * |
sahilmgandhi | 18:6a4db94011d3 | 229 | * \code |
sahilmgandhi | 18:6a4db94011d3 | 230 | #define USART_SERIAL &USARTD0 |
sahilmgandhi | 18:6a4db94011d3 | 231 | #define USART_SERIAL_BAUDRATE 9600 |
sahilmgandhi | 18:6a4db94011d3 | 232 | #define USART_SERIAL_CHAR_LENGTH US_MR_CHRL_8_BIT |
sahilmgandhi | 18:6a4db94011d3 | 233 | #define USART_SERIAL_PARITY US_MR_PAR_NO |
sahilmgandhi | 18:6a4db94011d3 | 234 | #define USART_SERIAL_STOP_BIT false |
sahilmgandhi | 18:6a4db94011d3 | 235 | \endcode |
sahilmgandhi | 18:6a4db94011d3 | 236 | * |
sahilmgandhi | 18:6a4db94011d3 | 237 | * Add to application initialization: |
sahilmgandhi | 18:6a4db94011d3 | 238 | * \code |
sahilmgandhi | 18:6a4db94011d3 | 239 | sysclk_init(); |
sahilmgandhi | 18:6a4db94011d3 | 240 | |
sahilmgandhi | 18:6a4db94011d3 | 241 | static usart_serial_options_t usart_options = { |
sahilmgandhi | 18:6a4db94011d3 | 242 | .baudrate = USART_SERIAL_BAUDRATE, |
sahilmgandhi | 18:6a4db94011d3 | 243 | .charlength = USART_SERIAL_CHAR_LENGTH, |
sahilmgandhi | 18:6a4db94011d3 | 244 | .paritytype = USART_SERIAL_PARITY, |
sahilmgandhi | 18:6a4db94011d3 | 245 | .stopbits = USART_SERIAL_STOP_BIT |
sahilmgandhi | 18:6a4db94011d3 | 246 | }; |
sahilmgandhi | 18:6a4db94011d3 | 247 | |
sahilmgandhi | 18:6a4db94011d3 | 248 | usart_serial_init(USART_SERIAL, &usart_options); |
sahilmgandhi | 18:6a4db94011d3 | 249 | \endcode |
sahilmgandhi | 18:6a4db94011d3 | 250 | * |
sahilmgandhi | 18:6a4db94011d3 | 251 | * \subsection serial_use_case_1_setup_flow Workflow |
sahilmgandhi | 18:6a4db94011d3 | 252 | * -# Initialize system clock: |
sahilmgandhi | 18:6a4db94011d3 | 253 | * - \code sysclk_init(); \endcode |
sahilmgandhi | 18:6a4db94011d3 | 254 | * -# Create USART options struct: |
sahilmgandhi | 18:6a4db94011d3 | 255 | * - \code |
sahilmgandhi | 18:6a4db94011d3 | 256 | static usart_serial_options_t usart_options = { |
sahilmgandhi | 18:6a4db94011d3 | 257 | .baudrate = USART_SERIAL_BAUDRATE, |
sahilmgandhi | 18:6a4db94011d3 | 258 | .charlength = USART_SERIAL_CHAR_LENGTH, |
sahilmgandhi | 18:6a4db94011d3 | 259 | .paritytype = USART_SERIAL_PARITY, |
sahilmgandhi | 18:6a4db94011d3 | 260 | .stopbits = USART_SERIAL_STOP_BIT |
sahilmgandhi | 18:6a4db94011d3 | 261 | }; |
sahilmgandhi | 18:6a4db94011d3 | 262 | \endcode |
sahilmgandhi | 18:6a4db94011d3 | 263 | * -# Initialize in RS232 mode: |
sahilmgandhi | 18:6a4db94011d3 | 264 | * - \code usart_serial_init(USART_SERIAL_EXAMPLE, &usart_options); \endcode |
sahilmgandhi | 18:6a4db94011d3 | 265 | * |
sahilmgandhi | 18:6a4db94011d3 | 266 | * \section serial_use_case_1_usage Usage steps |
sahilmgandhi | 18:6a4db94011d3 | 267 | * |
sahilmgandhi | 18:6a4db94011d3 | 268 | * \subsection serial_use_case_1_usage_code Example code |
sahilmgandhi | 18:6a4db94011d3 | 269 | * Add to, e.g., main loop in application C-file: |
sahilmgandhi | 18:6a4db94011d3 | 270 | * \code |
sahilmgandhi | 18:6a4db94011d3 | 271 | usart_serial_write_packet(USART_SERIAL, "Test String", strlen("Test String")); |
sahilmgandhi | 18:6a4db94011d3 | 272 | \endcode |
sahilmgandhi | 18:6a4db94011d3 | 273 | * |
sahilmgandhi | 18:6a4db94011d3 | 274 | * \subsection serial_use_case_1_usage_flow Workflow |
sahilmgandhi | 18:6a4db94011d3 | 275 | * -# Write a string of text to the USART: |
sahilmgandhi | 18:6a4db94011d3 | 276 | * - \code usart_serial_write_packet(USART_SERIAL, "Test String", strlen("Test String")); \endcode |
sahilmgandhi | 18:6a4db94011d3 | 277 | */ |
sahilmgandhi | 18:6a4db94011d3 | 278 | |
sahilmgandhi | 18:6a4db94011d3 | 279 | #endif /* SERIAL_PLATFORM_H_INCLUDED */ |