Update platform drivers
inc/uart.h@9:9e247b9c9abf, 2020-06-15 (annotated)
- Committer:
- EndaKilgarriff
- Date:
- Mon Jun 15 13:03:55 2020 +0000
- Revision:
- 9:9e247b9c9abf
- Include the following libraries:; - crc; - crc8; - uart; - util; - Add microsecond delay; - Move baud rate definition to mbed_app.json file; - Add bit shift for I2C slave address; - Check error for redefinition; - Make gpio handling more robust;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EndaKilgarriff | 9:9e247b9c9abf | 1 | /***************************************************************************//** |
EndaKilgarriff | 9:9e247b9c9abf | 2 | * @file uart.h |
EndaKilgarriff | 9:9e247b9c9abf | 3 | * @brief Header file of UART interface. |
EndaKilgarriff | 9:9e247b9c9abf | 4 | * @author Cristian Pop (cristian.pop@analog.com) |
EndaKilgarriff | 9:9e247b9c9abf | 5 | ******************************************************************************** |
EndaKilgarriff | 9:9e247b9c9abf | 6 | * Copyright 2019(c) Analog Devices, Inc. |
EndaKilgarriff | 9:9e247b9c9abf | 7 | * |
EndaKilgarriff | 9:9e247b9c9abf | 8 | * All rights reserved. |
EndaKilgarriff | 9:9e247b9c9abf | 9 | * |
EndaKilgarriff | 9:9e247b9c9abf | 10 | * Redistribution and use in source and binary forms, with or without |
EndaKilgarriff | 9:9e247b9c9abf | 11 | * modification, are permitted provided that the following conditions are met: |
EndaKilgarriff | 9:9e247b9c9abf | 12 | * - Redistributions of source code must retain the above copyright |
EndaKilgarriff | 9:9e247b9c9abf | 13 | * notice, this list of conditions and the following disclaimer. |
EndaKilgarriff | 9:9e247b9c9abf | 14 | * - Redistributions in binary form must reproduce the above copyright |
EndaKilgarriff | 9:9e247b9c9abf | 15 | * notice, this list of conditions and the following disclaimer in |
EndaKilgarriff | 9:9e247b9c9abf | 16 | * the documentation and/or other materials provided with the |
EndaKilgarriff | 9:9e247b9c9abf | 17 | * distribution. |
EndaKilgarriff | 9:9e247b9c9abf | 18 | * - Neither the name of Analog Devices, Inc. nor the names of its |
EndaKilgarriff | 9:9e247b9c9abf | 19 | * contributors may be used to endorse or promote products derived |
EndaKilgarriff | 9:9e247b9c9abf | 20 | * from this software without specific prior written permission. |
EndaKilgarriff | 9:9e247b9c9abf | 21 | * - The use of this software may or may not infringe the patent rights |
EndaKilgarriff | 9:9e247b9c9abf | 22 | * of one or more patent holders. This license does not release you |
EndaKilgarriff | 9:9e247b9c9abf | 23 | * from the requirement that you obtain separate licenses from these |
EndaKilgarriff | 9:9e247b9c9abf | 24 | * patent holders to use this software. |
EndaKilgarriff | 9:9e247b9c9abf | 25 | * - Use of the software either in source or binary form, must be run |
EndaKilgarriff | 9:9e247b9c9abf | 26 | * on or directly connected to an Analog Devices Inc. component. |
EndaKilgarriff | 9:9e247b9c9abf | 27 | * |
EndaKilgarriff | 9:9e247b9c9abf | 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
EndaKilgarriff | 9:9e247b9c9abf | 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
EndaKilgarriff | 9:9e247b9c9abf | 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
EndaKilgarriff | 9:9e247b9c9abf | 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
EndaKilgarriff | 9:9e247b9c9abf | 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
EndaKilgarriff | 9:9e247b9c9abf | 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
EndaKilgarriff | 9:9e247b9c9abf | 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
EndaKilgarriff | 9:9e247b9c9abf | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
EndaKilgarriff | 9:9e247b9c9abf | 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
EndaKilgarriff | 9:9e247b9c9abf | 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
EndaKilgarriff | 9:9e247b9c9abf | 38 | *******************************************************************************/ |
EndaKilgarriff | 9:9e247b9c9abf | 39 | #ifndef UART_H_ |
EndaKilgarriff | 9:9e247b9c9abf | 40 | #define UART_H_ |
EndaKilgarriff | 9:9e247b9c9abf | 41 | |
EndaKilgarriff | 9:9e247b9c9abf | 42 | /******************************************************************************/ |
EndaKilgarriff | 9:9e247b9c9abf | 43 | /***************************** Include Files **********************************/ |
EndaKilgarriff | 9:9e247b9c9abf | 44 | /******************************************************************************/ |
EndaKilgarriff | 9:9e247b9c9abf | 45 | |
EndaKilgarriff | 9:9e247b9c9abf | 46 | #include <stdint.h> |
EndaKilgarriff | 9:9e247b9c9abf | 47 | |
EndaKilgarriff | 9:9e247b9c9abf | 48 | /******************************************************************************/ |
EndaKilgarriff | 9:9e247b9c9abf | 49 | /*************************** Types Declarations *******************************/ |
EndaKilgarriff | 9:9e247b9c9abf | 50 | /******************************************************************************/ |
EndaKilgarriff | 9:9e247b9c9abf | 51 | |
EndaKilgarriff | 9:9e247b9c9abf | 52 | /** |
EndaKilgarriff | 9:9e247b9c9abf | 53 | * @struct uart_init_param |
EndaKilgarriff | 9:9e247b9c9abf | 54 | * @brief Structure holding the parameters for UART initialization |
EndaKilgarriff | 9:9e247b9c9abf | 55 | */ |
EndaKilgarriff | 9:9e247b9c9abf | 56 | struct uart_init_param { |
EndaKilgarriff | 9:9e247b9c9abf | 57 | /** UART Device ID */ |
EndaKilgarriff | 9:9e247b9c9abf | 58 | uint8_t device_id; |
EndaKilgarriff | 9:9e247b9c9abf | 59 | /** UART Baud Rate */ |
EndaKilgarriff | 9:9e247b9c9abf | 60 | uint32_t baud_rate; |
EndaKilgarriff | 9:9e247b9c9abf | 61 | /** UART extra parameters (device specific) */ |
EndaKilgarriff | 9:9e247b9c9abf | 62 | void *extra; |
EndaKilgarriff | 9:9e247b9c9abf | 63 | }; |
EndaKilgarriff | 9:9e247b9c9abf | 64 | |
EndaKilgarriff | 9:9e247b9c9abf | 65 | /** |
EndaKilgarriff | 9:9e247b9c9abf | 66 | * @struct uart_desc |
EndaKilgarriff | 9:9e247b9c9abf | 67 | * @brief Stucture holding the UART descriptor. |
EndaKilgarriff | 9:9e247b9c9abf | 68 | */ |
EndaKilgarriff | 9:9e247b9c9abf | 69 | struct uart_desc { |
EndaKilgarriff | 9:9e247b9c9abf | 70 | /** UART Device ID */ |
EndaKilgarriff | 9:9e247b9c9abf | 71 | uint8_t device_id; |
EndaKilgarriff | 9:9e247b9c9abf | 72 | /** UART Baud Rate */ |
EndaKilgarriff | 9:9e247b9c9abf | 73 | uint32_t baud_rate; |
EndaKilgarriff | 9:9e247b9c9abf | 74 | /** Callback to be called when an operation is done (optional) */ |
EndaKilgarriff | 9:9e247b9c9abf | 75 | void (*callback)(void *callback_ctx, uint32_t event, |
EndaKilgarriff | 9:9e247b9c9abf | 76 | void *extra); |
EndaKilgarriff | 9:9e247b9c9abf | 77 | /** Parameter to be passed to the callback as app_param */ |
EndaKilgarriff | 9:9e247b9c9abf | 78 | void *callback_ctx; |
EndaKilgarriff | 9:9e247b9c9abf | 79 | /** UART extra parameters (device specific) */ |
EndaKilgarriff | 9:9e247b9c9abf | 80 | void *extra; |
EndaKilgarriff | 9:9e247b9c9abf | 81 | }; |
EndaKilgarriff | 9:9e247b9c9abf | 82 | |
EndaKilgarriff | 9:9e247b9c9abf | 83 | /******************************************************************************/ |
EndaKilgarriff | 9:9e247b9c9abf | 84 | /************************ Functions Declarations ******************************/ |
EndaKilgarriff | 9:9e247b9c9abf | 85 | /******************************************************************************/ |
EndaKilgarriff | 9:9e247b9c9abf | 86 | |
EndaKilgarriff | 9:9e247b9c9abf | 87 | /* Read data from UART. Blocking function */ |
EndaKilgarriff | 9:9e247b9c9abf | 88 | int32_t uart_read(struct uart_desc *desc, uint8_t *data, uint32_t bytes_number); |
EndaKilgarriff | 9:9e247b9c9abf | 89 | |
EndaKilgarriff | 9:9e247b9c9abf | 90 | /* Write data to UART. Blocking function */ |
EndaKilgarriff | 9:9e247b9c9abf | 91 | int32_t uart_write(struct uart_desc *desc, const uint8_t *data, |
EndaKilgarriff | 9:9e247b9c9abf | 92 | uint32_t bytes_number); |
EndaKilgarriff | 9:9e247b9c9abf | 93 | |
EndaKilgarriff | 9:9e247b9c9abf | 94 | /* Read data from UART. Non blocking function */ |
EndaKilgarriff | 9:9e247b9c9abf | 95 | int32_t uart_read_nonblocking(struct uart_desc *desc, uint8_t *data, |
EndaKilgarriff | 9:9e247b9c9abf | 96 | uint32_t bytes_number); |
EndaKilgarriff | 9:9e247b9c9abf | 97 | |
EndaKilgarriff | 9:9e247b9c9abf | 98 | /* Write data to UART. Non blocking function*/ |
EndaKilgarriff | 9:9e247b9c9abf | 99 | int32_t uart_write_nonblocking(struct uart_desc *desc, const uint8_t *data, |
EndaKilgarriff | 9:9e247b9c9abf | 100 | uint32_t bytes_number); |
EndaKilgarriff | 9:9e247b9c9abf | 101 | |
EndaKilgarriff | 9:9e247b9c9abf | 102 | /* Initialize the UART communication peripheral. */ |
EndaKilgarriff | 9:9e247b9c9abf | 103 | int32_t uart_init(struct uart_desc **desc, struct uart_init_param *param); |
EndaKilgarriff | 9:9e247b9c9abf | 104 | |
EndaKilgarriff | 9:9e247b9c9abf | 105 | /* Free the resources allocated by uart_init(). */ |
EndaKilgarriff | 9:9e247b9c9abf | 106 | int32_t uart_remove(struct uart_desc *desc); |
EndaKilgarriff | 9:9e247b9c9abf | 107 | |
EndaKilgarriff | 9:9e247b9c9abf | 108 | /* Check if UART errors occurred. */ |
EndaKilgarriff | 9:9e247b9c9abf | 109 | uint32_t uart_get_errors(struct uart_desc *desc); |
EndaKilgarriff | 9:9e247b9c9abf | 110 | |
EndaKilgarriff | 9:9e247b9c9abf | 111 | #endif /* UART_H_ */ |