uartmux 2.0.0.0
uartmux.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef UARTMUX_H
36#define UARTMUX_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_uart.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define UARTMUX_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.inh = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.a = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71 cfg.b = MIKROBUS( mikrobus, MIKROBUS_PWM )
78#define UARTMUX_RETVAL uint8_t
79
80#define UARTMUX_OK 0x00
81#define UARTMUX_INIT_ERROR 0xFF
88#define UARTMUX_PIN_STATE_HIGH 1
89#define UARTMUX_PIN_STATE_LOW 0
96#define UARTMUX_STATE_A_CHANNEL_1 0
97#define UARTMUX_STATE_B_CHANNEL_1 0
104#define UARTMUX_STATE_A_CHANNEL_2 1
105#define UARTMUX_STATE_B_CHANNEL_2 0
112#define UARTMUX_STATE_A_CHANNEL_3 0
113#define UARTMUX_STATE_B_CHANNEL_3 1
120#define UARTMUX_STATE_A_CHANNEL_4 1
121#define UARTMUX_STATE_B_CHANNEL_4 1
128#define DRV_RX_BUFFER_SIZE 500
131 // End group macro
132// --------------------------------------------------------------- PUBLIC TYPES
138typedef struct
139{
140 uint8_t state_a;
141 uint8_t state_b;
142
144
148typedef struct
149{
150 // Output pins
151
152 digital_out_t inh;
153 digital_out_t a;
154 digital_out_t b;
155
156 // Modules
157
158 uart_t uart;
159
160 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
161 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
162
163 //uartmux_channel_t channel;
164
165} uartmux_t;
166
170typedef struct
171{
172 // Communication gpio pins
173
174 pin_name_t rx_pin;
175 pin_name_t tx_pin;
176
177 // Additional gpio pins
178
179 pin_name_t inh;
180 pin_name_t a;
181 pin_name_t b;
182
183 // static variable
184
185 uint32_t baud_rate; // Clock speed.
187 uart_data_bits_t data_bit; // Data bits.
188 uart_parity_t parity_bit; // Parity bit.
189 uart_stop_bits_t stop_bit; // Stop bits.
190
192
196typedef uint8_t uartmux_error_t;
197
198 // End types group
199// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
200
206#ifdef __cplusplus
207extern "C"{
208#endif
209
219
228
237void uartmux_generic_write ( uartmux_t *ctx, char *data_buf, uint16_t data_len, uartmux_channel_t *channel );
248int32_t uartmux_generic_read ( uartmux_t *ctx, char *data_buf, uint16_t max_len, uartmux_channel_t *channel );
249
256void uartmux_set_inhibit_communication ( uartmux_t *ctx, uint8_t state );
257
265
266#ifdef __cplusplus
267}
268#endif
269#endif // _UARTMUX_H_
270
271 // End public_function group
273
274// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition uartmux.h:128
#define UARTMUX_RETVAL
Definition uartmux.h:78
void uartmux_set_inhibit_communication(uartmux_t *ctx, uint8_t state)
Set INT pin.
UARTMUX_RETVAL uartmux_init(uartmux_t *ctx, uartmux_cfg_t *cfg)
Initialization function.
void uartmux_choose_channel(uartmux_t *ctx, uartmux_channel_t *channel)
Choose channel.
void uartmux_cfg_setup(uartmux_cfg_t *cfg)
Config Object Initialization function.
int32_t uartmux_generic_read(uartmux_t *ctx, char *data_buf, uint16_t max_len, uartmux_channel_t *channel)
Generic read function.
void uartmux_generic_write(uartmux_t *ctx, char *data_buf, uint16_t data_len, uartmux_channel_t *channel)
Generic write function.
uint8_t uartmux_error_t
Error type.
Definition uartmux.h:196
Click configuration structure definition.
Definition uartmux.h:171
uint32_t baud_rate
Definition uartmux.h:185
pin_name_t inh
Definition uartmux.h:179
bool uart_blocking
Definition uartmux.h:186
uart_data_bits_t data_bit
Definition uartmux.h:187
pin_name_t b
Definition uartmux.h:181
pin_name_t tx_pin
Definition uartmux.h:175
pin_name_t a
Definition uartmux.h:180
pin_name_t rx_pin
Definition uartmux.h:174
uart_stop_bits_t stop_bit
Definition uartmux.h:189
uart_parity_t parity_bit
Definition uartmux.h:188
Definition uartmux.h:139
uint8_t state_b
Definition uartmux.h:141
uint8_t state_a
Definition uartmux.h:140
Click ctx object definition.
Definition uartmux.h:149
digital_out_t a
Definition uartmux.h:153
digital_out_t inh
Definition uartmux.h:152
uart_t uart
Definition uartmux.h:158
digital_out_t b
Definition uartmux.h:154