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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define UARTMUX_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.inh = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.a = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.b = MIKROBUS( mikrobus, MIKROBUS_PWM )
58 
64 #define UARTMUX_RETVAL uint8_t
65 
66 #define UARTMUX_OK 0x00
67 #define UARTMUX_INIT_ERROR 0xFF
68 
74 #define UARTMUX_PIN_STATE_HIGH 1
75 #define UARTMUX_PIN_STATE_LOW 0
76 
82 #define UARTMUX_STATE_A_CHANNEL_1 0
83 #define UARTMUX_STATE_B_CHANNEL_1 0
84 
90 #define UARTMUX_STATE_A_CHANNEL_2 1
91 #define UARTMUX_STATE_B_CHANNEL_2 0
92 
98 #define UARTMUX_STATE_A_CHANNEL_3 0
99 #define UARTMUX_STATE_B_CHANNEL_3 1
100 
106 #define UARTMUX_STATE_A_CHANNEL_4 1
107 #define UARTMUX_STATE_B_CHANNEL_4 1
108 
114 #define DRV_RX_BUFFER_SIZE 500
115  // End group macro
118 // --------------------------------------------------------------- PUBLIC TYPES
124 typedef struct
125 {
126  uint8_t state_a;
127  uint8_t state_b;
128 
130 
134 typedef struct
135 {
136  // Output pins
137 
138  digital_out_t inh;
139  digital_out_t a;
140  digital_out_t b;
141 
142  // Modules
143 
144  uart_t uart;
145 
146  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
147  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
148 
149  //uartmux_channel_t channel;
150 
151 } uartmux_t;
152 
156 typedef struct
157 {
158  // Communication gpio pins
159 
160  pin_name_t rx_pin;
161  pin_name_t tx_pin;
162 
163  // Additional gpio pins
164 
165  pin_name_t inh;
166  pin_name_t a;
167  pin_name_t b;
168 
169  // static variable
170 
171  uint32_t baud_rate; // Clock speed.
173  uart_data_bits_t data_bit; // Data bits.
174  uart_parity_t parity_bit; // Parity bit.
175  uart_stop_bits_t stop_bit; // Stop bits.
176 
177 } uartmux_cfg_t;
178 
182 typedef uint8_t uartmux_error_t;
183  // End types group
185 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
186 
192 #ifdef __cplusplus
193 extern "C"{
194 #endif
195 
205 
214 
223 void uartmux_generic_write ( uartmux_t *ctx, char *data_buf, uint16_t data_len, uartmux_channel_t *channel );
234 int32_t uartmux_generic_read ( uartmux_t *ctx, char *data_buf, uint16_t max_len, uartmux_channel_t *channel );
235 
242 void uartmux_set_inhibit_communication ( uartmux_t *ctx, uint8_t state );
243 
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif // _UARTMUX_H_
256  // End public_function group
259 
260 // ------------------------------------------------------------------------- END
uartmux_channel_t::state_a
uint8_t state_a
Definition: uartmux.h:126
uartmux_t::b
digital_out_t b
Definition: uartmux.h:140
uartmux_cfg_t::b
pin_name_t b
Definition: uartmux.h:167
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: uartmux.h:114
uartmux_t
Click ctx object definition.
Definition: uartmux.h:135
uartmux_channel_t::state_b
uint8_t state_b
Definition: uartmux.h:127
uartmux_choose_channel
void uartmux_choose_channel(uartmux_t *ctx, uartmux_channel_t *channel)
Choose channel.
uartmux_cfg_t::uart_blocking
bool uart_blocking
Definition: uartmux.h:172
uartmux_cfg_setup
void uartmux_cfg_setup(uartmux_cfg_t *cfg)
Config Object Initialization function.
uartmux_t::a
digital_out_t a
Definition: uartmux.h:139
UARTMUX_RETVAL
#define UARTMUX_RETVAL
Definition: uartmux.h:64
uartmux_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: uartmux.h:173
uartmux_error_t
uint8_t uartmux_error_t
Error type.
Definition: uartmux.h:182
uartmux_channel_t
Definition: uartmux.h:125
uartmux_set_inhibit_communication
void uartmux_set_inhibit_communication(uartmux_t *ctx, uint8_t state)
Set INT pin.
uartmux_cfg_t
Click configuration structure definition.
Definition: uartmux.h:157
uartmux_cfg_t::inh
pin_name_t inh
Definition: uartmux.h:165
uartmux_generic_write
void uartmux_generic_write(uartmux_t *ctx, char *data_buf, uint16_t data_len, uartmux_channel_t *channel)
Generic write function.
uartmux_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: uartmux.h:175
uartmux_init
UARTMUX_RETVAL uartmux_init(uartmux_t *ctx, uartmux_cfg_t *cfg)
Initialization function.
uartmux_cfg_t::tx_pin
pin_name_t tx_pin
Definition: uartmux.h:161
uartmux_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: uartmux.h:174
uartmux_t::uart
uart_t uart
Definition: uartmux.h:144
uartmux_cfg_t::a
pin_name_t a
Definition: uartmux.h:166
uartmux_generic_read
int32_t uartmux_generic_read(uartmux_t *ctx, char *data_buf, uint16_t max_len, uartmux_channel_t *channel)
Generic read function.
uartmux_t::inh
digital_out_t inh
Definition: uartmux.h:138
uartmux_cfg_t::rx_pin
pin_name_t rx_pin
Definition: uartmux.h:160
uartmux_cfg_t::baud_rate
uint32_t baud_rate
Definition: uartmux.h:171