no-OS
Classes | Macros | Functions | Variables
uart.c File Reference

Implementation of UART driver for ADuCM302x. More...

#include <drivers/uart/adi_uart.h>
#include <stdlib.h>
#include "uart.h"
#include "irq.h"
#include "uart_extra.h"
#include "util.h"
Include dependency graph for uart.c:

Classes

struct  baud_desc
 Structure of an element from baud_rates_26MHz. The baud rate is calculated with the formula: Baudrate = (CLK_FREQ / (div_m + div_n/2048) * pow(2,osr+2) * div_c)). More...
 
struct  op_desc
 It stores the state of a operation. More...
 
struct  aducm_uart_desc
 Stores specific parameter needed by the UART driver for internal operations. More...
 

Macros

#define MAX_BYTES   1024u
 
#define CLK_FREQ   26000000u
 
#define BAUDS_NB   10u
 
#define NUM_UART_DEVICES   1
 

Functions

int32_t uart_read (struct uart_desc *desc, uint8_t *data, uint32_t bytes_number)
 Read data from UART. Blocking function. More...
 
int32_t uart_write (struct uart_desc *desc, const uint8_t *data, uint32_t bytes_number)
 Write data to UART. Blocking function. More...
 
int32_t uart_read_nonblocking (struct uart_desc *desc, uint8_t *data, uint32_t bytes_number)
 Submit reading buffer to the UART driver. More...
 
int32_t uart_write_nonblocking (struct uart_desc *desc, const uint8_t *data, uint32_t bytes_number)
 Submit writting buffer to the UART driver. More...
 
int32_t uart_init (struct uart_desc **desc, struct uart_init_param *param)
 Initialize the UART communication peripheral. More...
 
int32_t uart_remove (struct uart_desc *desc)
 Free the resources allocated by uart_init() More...
 
uint32_t uart_get_errors (struct uart_desc *desc)
 Free the resources allocated by uart_init() More...
 

Variables

const struct baud_desc baud_rates_26MHz [BAUDS_NB]
 

Detailed Description

Implementation of UART driver for ADuCM302x.

Author
Mihail Chindris (mihai.nosp@m.l.ch.nosp@m.indri.nosp@m.s@an.nosp@m.alog..nosp@m.com)

Copyright 2019(c) Analog Devices, Inc.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Macro Definition Documentation

◆ BAUDS_NB

#define BAUDS_NB   10u

◆ CLK_FREQ

#define CLK_FREQ   26000000u

◆ MAX_BYTES

#define MAX_BYTES   1024u

◆ NUM_UART_DEVICES

#define NUM_UART_DEVICES   1

In ADuCM302x UART0 is available

Function Documentation

◆ uart_get_errors()

uint32_t uart_get_errors ( struct uart_desc desc)

Free the resources allocated by uart_init()

Parameters
descDescriptor of the UART device
Returns
SUCCESS in case of success, FAILURE otherwise.

◆ uart_init()

int32_t uart_init ( struct uart_desc **  desc,
struct uart_init_param param 
)

Initialize the UART communication peripheral.

To configure the UART, the user must set the extra parameter from param with a pointer to the configured platform specific structure aducm_uart_init_param .

Parameters
descDescriptor of the UART device used in the call of the drivers functions
paramDescriptor used to configure the UART device
Returns
SUCCESS in case of success, FAILURE otherwise.

◆ uart_read()

int32_t uart_read ( struct uart_desc desc,
uint8_t *  data,
uint32_t  bytes_number 
)

Read data from UART. Blocking function.

Parameters
descDescriptor of the UART device
dataBuffer where data will be read
bytes_numberNumber of bytes to be read. Between 1 and 1024
Returns
SUCCESS in case of success, FAILURE otherwise.

◆ uart_read_nonblocking()

int32_t uart_read_nonblocking ( struct uart_desc desc,
uint8_t *  data,
uint32_t  bytes_number 
)

Submit reading buffer to the UART driver.

Buffer is used until bytes_number bytes are read.

Parameters
descDescriptor of the UART device
dataBuffer where data will be read
bytes_numberNumber of bytes to be read.
Returns
SUCCESS in case of success, FAILURE otherwise.

◆ uart_remove()

int32_t uart_remove ( struct uart_desc desc)

Free the resources allocated by uart_init()

Parameters
descDescriptor of the UART device
Returns
SUCCESS in case of success, FAILURE otherwise.

◆ uart_write()

int32_t uart_write ( struct uart_desc desc,
const uint8_t *  data,
uint32_t  bytes_number 
)

Write data to UART. Blocking function.

Parameters
descDescriptor of the UART device
dataBuffer with the data to be written
bytes_numberNumber of bytes to be written. Between 1 and 1024
Returns
SUCCESS in case of success, FAILURE otherwise.

◆ uart_write_nonblocking()

int32_t uart_write_nonblocking ( struct uart_desc desc,
const uint8_t *  data,
uint32_t  bytes_number 
)

Submit writting buffer to the UART driver.

Data from the buffer is sent over the UART, the function returns immediately.

Parameters
descDescriptor of the UART device
dataBuffer where data will be written
bytes_numberNumber of bytes to be written.
Returns
SUCCESS in case of success, FAILURE otherwise.

Variable Documentation

◆ baud_rates_26MHz

const struct baud_desc baud_rates_26MHz[BAUDS_NB]
Initial value:
= {
{9600, 1078, 3, 24, 3},
{19200, 1078, 3, 12, 3},
{38400, 1321, 3, 8, 2},
{57600, 1078, 3, 4, 3},
{115200, 1563, 1, 4, 3},
{230400, 1563, 1, 2, 3},
{460800, 1563, 1, 1, 3},
{921600, 1563, 1, 1, 2},
{1000000,1280, 1, 1, 2},
{1500000, 171, 1, 1, 2}
}

Stores calculated baud rates and parameters