uartmux2  2.0.0.0
uartmux2.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef UARTMUX2_H
29 #define UARTMUX2_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
69 // TODO -- dodati makroe koji definisu adrese registara
70  // uartmux2_reg
72 
93 #define DRV_BUFFER_SIZE 200
94  // uartmux2_set
96 
107 #define UARTMUX2_SUCCESS 0
108 #define UARTMUX2_ERROR -1
109 
110  // status
112 
123 #define UARTMUX2_OP_MODE_NORMAL 0x00
124 #define UARTMUX2_OP_MODE_POWER_DOWN 0x01
125 
126  // op_mode
128 
139 #define UARTMUX2_CHANNEL_0 0
140 #define UARTMUX2_CHANNEL_1 1
141 #define UARTMUX2_CHANNEL_2 2
142 #define UARTMUX2_CHANNEL_3 3
143 
144  // mux_ch
146 
161 #define UARTMUX2_MAP_MIKROBUS( cfg, mikrobus ) \
162  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
163  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
164  cfg.off = MIKROBUS( mikrobus, MIKROBUS_AN ); \
165  cfg.a1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
166  cfg.a0 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
167  cfg.on = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
168  cfg.inv = MIKROBUS( mikrobus, MIKROBUS_INT );
169  // uartmux2_map // uartmux2
172 
177 typedef struct
178 {
179  // Output pins
180 
181  digital_out_t off;
182  digital_out_t a1;
183  digital_out_t a0;
184  digital_out_t on;
186  // Input pins
187 
188  digital_in_t inv;
190  // Modules
191 
192  uart_t uart;
194  // Buffers
195 
196  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
197  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
199 } uartmux2_t;
200 
205 typedef struct
206 {
207  // Communication gpio pins
208 
209  pin_name_t rx_pin;
210  pin_name_t tx_pin;
212  // Additional gpio pins
213 
214  pin_name_t off;
215  pin_name_t a1;
216  pin_name_t a0;
217  pin_name_t on;
218  pin_name_t inv;
220  // Static variable
221 
222  uint32_t baud_rate;
224  uart_data_bits_t data_bit;
225  uart_parity_t parity_bit;
226  uart_stop_bits_t stop_bit;
229 
246 
262 
274 
288 err_t uartmux2_generic_write ( uartmux2_t *ctx, char *data_buf, uint16_t len );
289 
303 err_t uartmux2_generic_read ( uartmux2_t *ctx, char *data_buf, uint16_t max_len );
304 
320 err_t uartmux2_set_operation_mode ( uartmux2_t *ctx, uint8_t op_mode );
321 
339 err_t uartmux2_set_channel ( uartmux2_t *ctx, uint8_t mux_ch );
340 
353 err_t uartmux2_send_data ( uartmux2_t *ctx, char *tx_data );
354 
368 
369 #ifdef __cplusplus
370 }
371 #endif
372 #endif // UARTMUX2_H
373  // uartmux2
375 
376 // ------------------------------------------------------------------------ END
uartmux2_set_operation_mode
err_t uartmux2_set_operation_mode(uartmux2_t *ctx, uint8_t op_mode)
UART MUX 2 set operation mode function.
uartmux2_cfg_t::baud_rate
uint32_t baud_rate
Definition: uartmux2.h:222
uartmux2_default_cfg
void uartmux2_default_cfg(uartmux2_t *ctx)
UART MUX 2 default configuration function.
uartmux2_cfg_t::a0
pin_name_t a0
Definition: uartmux2.h:216
uartmux2_cfg_t::on
pin_name_t on
Definition: uartmux2.h:217
uartmux2_set_channel
err_t uartmux2_set_channel(uartmux2_t *ctx, uint8_t mux_ch)
UART MUX 2 set channel function.
uartmux2_cfg_setup
void uartmux2_cfg_setup(uartmux2_cfg_t *cfg)
UART MUX 2 configuration object setup function.
uartmux2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: uartmux2.h:225
uartmux2_t::on
digital_out_t on
Definition: uartmux2.h:184
uartmux2_generic_read
err_t uartmux2_generic_read(uartmux2_t *ctx, char *data_buf, uint16_t max_len)
UART MUX 2 data reading function.
uartmux2_t::off
digital_out_t off
Definition: uartmux2.h:181
uartmux2_cfg_t::a1
pin_name_t a1
Definition: uartmux2.h:215
uartmux2_t::a0
digital_out_t a0
Definition: uartmux2.h:183
uartmux2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: uartmux2.h:210
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
UART MUX 2 description setting.
Definition: uartmux2.h:93
uartmux2_t::uart
uart_t uart
Definition: uartmux2.h:192
uartmux2_cfg_t::off
pin_name_t off
Definition: uartmux2.h:214
uartmux2_init
err_t uartmux2_init(uartmux2_t *ctx, uartmux2_cfg_t *cfg)
UART MUX 2 initialization function.
uartmux2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: uartmux2.h:226
uartmux2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: uartmux2.h:209
uartmux2_t
UART MUX 2 Click context object.
Definition: uartmux2.h:178
uartmux2_cfg_t::inv
pin_name_t inv
Definition: uartmux2.h:218
uartmux2_generic_write
err_t uartmux2_generic_write(uartmux2_t *ctx, char *data_buf, uint16_t len)
UART MUX 2 data writing function.
uartmux2_t::inv
digital_in_t inv
Definition: uartmux2.h:188
uartmux2_send_data
err_t uartmux2_send_data(uartmux2_t *ctx, char *tx_data)
UART MUX 2 data writing function.
uartmux2_cfg_t::uart_blocking
bool uart_blocking
Definition: uartmux2.h:223
uartmux2_cfg_t
UART MUX 2 Click configuration object.
Definition: uartmux2.h:206
uartmux2_get_inv_status
uint8_t uartmux2_get_inv_status(uartmux2_t *ctx)
UART MUX 2 get INV pin status function.
uartmux2_t::a1
digital_out_t a1
Definition: uartmux2.h:182
uartmux2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: uartmux2.h:224