drivers/uart/uart.h
Go to the documentation of this file.
1 
33 /*
34  * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
35  */
36 
37 #ifndef UART_H_INCLUDED
38 #define UART_H_INCLUDED
39 
40 #include "compiler.h"
41 
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 
50 /* UART internal div factor for sampling */
51 #define UART_MCK_DIV 16
52 /* Div factor to get the maximum baud rate */
53 #define UART_MCK_DIV_MIN_FACTOR 1
54 /* Div factor to get the minimum baud rate */
55 #define UART_MCK_DIV_MAX_FACTOR 65535
56 
58 typedef struct sam_uart_opt {
60  uint32_t ul_mck;
62  uint32_t ul_baudrate;
64  uint32_t ul_mode;
66 
67 uint32_t uart_init(Uart *p_uart, const sam_uart_opt_t *p_uart_opt);
68 void uart_enable_tx(Uart *p_uart);
69 void uart_disable_tx(Uart *p_uart);
70 void uart_reset_tx(Uart *p_uart);
71 void uart_enable_rx(Uart *p_uart);
72 void uart_disable_rx(Uart *p_uart);
73 void uart_reset_rx(Uart *p_uart);
74 void uart_enable(Uart *p_uart);
75 void uart_disable(Uart *p_uart);
76 void uart_reset(Uart *p_uart);
77 void uart_enable_interrupt(Uart *p_uart, uint32_t ul_sources);
78 void uart_disable_interrupt(Uart *p_uart, uint32_t ul_sources);
79 uint32_t uart_get_interrupt_mask(Uart *p_uart);
80 uint32_t uart_get_status(Uart *p_uart);
81 void uart_reset_status(Uart *p_uart);
82 uint32_t uart_is_tx_ready(Uart *p_uart);
83 uint32_t uart_is_tx_empty(Uart *p_uart);
84 uint32_t uart_is_rx_ready(Uart *p_uart);
85 uint32_t uart_is_tx_buf_empty(Uart *p_uart);
86 void uart_set_clock_divisor(Uart *p_uart, uint16_t us_divisor);
87 uint32_t uart_write(Uart *p_uart, const uint8_t uc_data);
88 uint32_t uart_read(Uart *p_uart, uint8_t *puc_data);
89 #if (!SAMV71 && !SAMV70 && !SAME70 && !SAMS70)
90 uint32_t uart_is_rx_buf_end(Uart *p_uart);
91 uint32_t uart_is_tx_buf_end(Uart *p_uart);
92 uint32_t uart_is_rx_buf_full(Uart *p_uart);
93 Pdc *uart_get_pdc_base(Uart *p_uart);
94 #endif
95 #if (SAMG53 || SAMG54 || SAMV71 || SAMV70 || SAME70 || SAMS70)
96 void uart_set_sleepwalking(Uart *p_uart, uint8_t ul_low_value,
97  bool cmpmode, bool cmppar, uint8_t ul_high_value);
98 void uart_set_write_protection(Uart *p_uart, bool flag);
99 #endif
100 
101 #if (SAM4C || SAM4CP || SAM4CM)
102 enum uart_optical_duty_cycle {
103  UART_MOD_CLK_DUTY_50_00 = UART_MR_OPT_DUTY_DUTY_50,
104  UART_MOD_CLK_DUTY_43_75 = UART_MR_OPT_DUTY_DUTY_43P75,
105  UART_MOD_CLK_DUTY_37_50 = UART_MR_OPT_DUTY_DUTY_37P5,
106  UART_MOD_CLK_DUTY_31_25 = UART_MR_OPT_DUTY_DUTY_31P25,
107  UART_MOD_CLK_DUTY_25_00 = UART_MR_OPT_DUTY_DUTY_25,
108  UART_MOD_CLK_DUTY_18_75 = UART_MR_OPT_DUTY_DUTY_18P75,
109  UART_MOD_CLK_DUTY_12_50 = UART_MR_OPT_DUTY_DUTY_12P5,
110  UART_MOD_CLK_DUTY_06_25 = UART_MR_OPT_DUTY_DUTY_6P25,
111 };
112 
113 enum uart_optical_cmp_threshold {
114  UART_RX_CMP_THRESHOLD_VDDIO_DIV_10_0 = UART_MR_OPT_CMPTH_VDDIO_DIV10,
115  UART_RX_CMP_THRESHOLD_VDDIO_DIV_5_0 = UART_MR_OPT_CMPTH_VDDIO_DIV5,
116  UART_RX_CMP_THRESHOLD_VDDIO_DIV_3_3 = UART_MR_OPT_CMPTH_VDDIO_DIV3P3,
117  UART_RX_CMP_THRESHOLD_VDDIO_DIV_2_5 = UART_MR_OPT_CMPTH_VDDIO_DIV2P5,
118  UART_RX_CMP_THRESHOLD_VDDIO_DIV_2_0 = UART_MR_OPT_CMPTH_VDDIO_DIV2,
119 };
120 
121 struct uart_config_optical {
122  /* UART Receive Data Inverted */
123  bool rx_inverted;
124  /* UART Modulated Data Inverted */
125  bool tx_inverted;
126  /* UART Receiver Digital Filter */
127  bool rx_filter;
128  /* Optical Link Clock Divider */
129  uint8_t clk_div;
130  /* Optical Link Modulation Clock Duty Cycle */
131  enum uart_optical_duty_cycle duty;
132  /* Receive Path Comparator Threshold */
133  enum uart_optical_cmp_threshold threshold;
134 };
135 
136 void uart_enable_optical_interface(Uart *p_uart);
137 void uart_disable_optical_interface(Uart *p_uart);
138 void uart_config_optical_interface(Uart *p_uart,
139  struct uart_config_optical *cfg);
140 #endif
141 
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 
150 #endif /* UART_H_INCLUDED */
Pdc * uart_get_pdc_base(Uart *p_uart)
Get UART PDC base address.
Definition: uart.c:420
void uart_reset_rx(Uart *p_uart)
Reset UART receiver.
Definition: uart.c:170
void uart_disable_tx(Uart *p_uart)
Disable UART transmitter.
Definition: uart.c:126
uint32_t ul_baudrate
uint32_t uart_is_tx_empty(Uart *p_uart)
Check if Transmit Hold Register is empty. Check if the last data written in UART_THR has been loaded ...
Definition: uart.c:288
void uart_set_clock_divisor(Uart *p_uart, uint16_t us_divisor)
Set UART clock divisor value.
Definition: uart.c:327
uint32_t uart_is_tx_buf_end(Uart *p_uart)
Check if one transmit buffer is sent out.
Definition: uart.c:395
Uart hardware registers.
uint32_t uart_read(Uart *p_uart, uint8_t *puc_data)
Read from UART Receive Holding Register. Before reading user should check if rx is ready...
Definition: uart.c:362
uint32_t uart_is_tx_buf_empty(Uart *p_uart)
Check if both transmit buffers are sent out.
Definition: uart.c:315
void uart_disable(Uart *p_uart)
Disable UART receiver and transmitter.
Definition: uart.c:192
void uart_enable(Uart *p_uart)
Enable UART receiver and transmitter.
Definition: uart.c:181
uint32_t uart_init(Uart *p_uart, const sam_uart_opt_t *p_uart_opt)
Configure UART with the specified parameters.
Definition: uart.c:81
Commonly used includes, types and macros.
void uart_enable_rx(Uart *p_uart)
Enable UART receiver.
Definition: uart.c:148
void uart_disable_rx(Uart *p_uart)
Disable UART receiver.
Definition: uart.c:159
void uart_disable_interrupt(Uart *p_uart, uint32_t ul_sources)
Disable UART interrupts.
Definition: uart.c:225
uint32_t uart_get_interrupt_mask(Uart *p_uart)
Read UART interrupt mask.
Definition: uart.c:236
uint32_t uart_is_rx_buf_end(Uart *p_uart)
Check if one receive buffer is filled.
Definition: uart.c:382
uint32_t uart_is_rx_ready(Uart *p_uart)
Check if Received data is ready. Check if data has been received and loaded in UART_RHR.
Definition: uart.c:302
Option list for UART peripheral initialization.
void uart_reset_status(Uart *p_uart)
Reset status bits.
Definition: uart.c:258
uint32_t uart_get_status(Uart *p_uart)
Get current status.
Definition: uart.c:248
uint32_t uart_write(Uart *p_uart, const uint8_t uc_data)
Write to UART Transmit Holding Register Before writing user should check if tx is ready (or empty)...
Definition: uart.c:342
struct sam_uart_opt sam_uart_opt_t
Option list for UART peripheral initialization.
uint32_t uart_is_rx_buf_full(Uart *p_uart)
Check if both receive buffers are full.
Definition: uart.c:408
void uart_reset_tx(Uart *p_uart)
Reset UART transmitter.
Definition: uart.c:137
void uart_enable_tx(Uart *p_uart)
Enable UART transmitter.
Definition: uart.c:115
uint32_t uart_is_tx_ready(Uart *p_uart)
Check if Transmit is Ready. Check if data has been loaded in UART_THR and is waiting to be loaded in ...
Definition: uart.c:273
void uart_reset(Uart *p_uart)
Reset UART receiver and transmitter.
Definition: uart.c:203
void uart_enable_interrupt(Uart *p_uart, uint32_t ul_sources)
Enable UART interrupts.
Definition: uart.c:215


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58