rs4857  2.1.0.0
rs4857.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 RS4857_H
29 #define RS4857_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_uart.h"
37 
59 #define RS4857_TX_DRV_BUFFER_SIZE 100
60 #define RS4857_RX_DRV_BUFFER_SIZE 300
61  // rs4857_cmd
63 
78 #define RS4857_MAP_MIKROBUS( cfg, mikrobus ) \
79  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
80  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
81  cfg.de = MIKROBUS( mikrobus, MIKROBUS_AN ); \
82  cfg.re = MIKROBUS( mikrobus, MIKROBUS_RST ); \
83  cfg.ret = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
84  cfg.tet = MIKROBUS( mikrobus, MIKROBUS_INT )
85  // rs4857_map // rs4857
88 
93 typedef struct
94 {
95  // Output pins
96  digital_out_t de;
97  digital_out_t re;
98  digital_out_t ret;
99  digital_out_t tet;
101  // Modules
102  uart_t uart;
104  // Buffers
105  char uart_rx_buffer[ RS4857_RX_DRV_BUFFER_SIZE ];
106  char uart_tx_buffer[ RS4857_TX_DRV_BUFFER_SIZE ];
108 } rs4857_t;
109 
114 typedef struct
115 {
116  // Communication gpio pins
117  pin_name_t rx_pin;
118  pin_name_t tx_pin;
120  // Additional gpio pins
121  pin_name_t de;
122  pin_name_t re;
123  pin_name_t ret;
124  pin_name_t tet;
126  // Static variable
127  uint32_t baud_rate;
129  uart_data_bits_t data_bit;
130  uart_parity_t parity_bit;
131  uart_stop_bits_t stop_bit;
133 } rs4857_cfg_t;
134 
139 typedef enum
140 {
142  RS4857_ERROR = -1
143 
145 
162 
176 err_t rs4857_init ( rs4857_t *ctx, rs4857_cfg_t *cfg );
177 
190 err_t rs4857_generic_write ( rs4857_t *ctx, char *data_in, uint16_t len );
191 
204 err_t rs4857_generic_read ( rs4857_t *ctx, char *data_out, uint16_t len );
205 
217 
229 
241 
253 
265 
277 
289 
301 
302 #ifdef __cplusplus
303 }
304 #endif
305 #endif // RS4857_H
306  // rs4857
308 
309 // ------------------------------------------------------------------------ END
rs4857_driver_disable
void rs4857_driver_disable(rs4857_t *ctx)
RS485 7 disable the driver function.
rs4857_driver_enable
void rs4857_driver_enable(rs4857_t *ctx)
RS485 7 enables the driver function.
rs4857_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rs4857.h:131
rs4857_init
err_t rs4857_init(rs4857_t *ctx, rs4857_cfg_t *cfg)
RS485 7 initialization function.
rs4857_receiver_disable
void rs4857_receiver_disable(rs4857_t *ctx)
RS485 7 disable the receiver function.
rs4857_t::uart
uart_t uart
Definition: rs4857.h:102
rs4857_cfg_t::de
pin_name_t de
Definition: rs4857.h:121
rs4857_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs4857.h:130
RS4857_ERROR
@ RS4857_ERROR
Definition: rs4857.h:142
rs4857_termination_xy_enable
void rs4857_termination_xy_enable(rs4857_t *ctx)
RS485 7 Y-Z termination enable function.
rs4857_generic_read
err_t rs4857_generic_read(rs4857_t *ctx, char *data_out, uint16_t len)
RS485 7 data reading function.
rs4857_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rs4857.h:129
rs4857_termination_xy_disable
void rs4857_termination_xy_disable(rs4857_t *ctx)
RS485 7 Y-Z termination disable function.
rs4857_t::de
digital_out_t de
Definition: rs4857.h:96
rs4857_cfg_t::uart_blocking
bool uart_blocking
Definition: rs4857.h:128
rs4857_t::tet
digital_out_t tet
Definition: rs4857.h:99
rs4857_generic_write
err_t rs4857_generic_write(rs4857_t *ctx, char *data_in, uint16_t len)
RS485 7 data writing function.
rs4857_t
RS485 7 Click context object.
Definition: rs4857.h:94
RS4857_OK
@ RS4857_OK
Definition: rs4857.h:141
RS4857_RX_DRV_BUFFER_SIZE
#define RS4857_RX_DRV_BUFFER_SIZE
Definition: rs4857.h:60
rs4857_t::re
digital_out_t re
Definition: rs4857.h:97
rs4857_cfg_t::ret
pin_name_t ret
Definition: rs4857.h:123
rs4857_receiver_enable
void rs4857_receiver_enable(rs4857_t *ctx)
RS485 7 enables the receiver function.
RS4857_TX_DRV_BUFFER_SIZE
#define RS4857_TX_DRV_BUFFER_SIZE
RS485 7 driver buffer size.
Definition: rs4857.h:59
rs4857_t::ret
digital_out_t ret
Definition: rs4857.h:98
rs4857_cfg_t
RS485 7 Click configuration object.
Definition: rs4857.h:115
rs4857_cfg_t::tet
pin_name_t tet
Definition: rs4857.h:124
rs4857_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs4857.h:117
rs4857_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs4857.h:118
rs4857_cfg_t::baud_rate
uint32_t baud_rate
Definition: rs4857.h:127
rs4857_cfg_t::re
pin_name_t re
Definition: rs4857.h:122
rs4857_termination_ab_disable
void rs4857_termination_ab_disable(rs4857_t *ctx)
RS485 7 A-B termination disable function.
rs4857_cfg_setup
void rs4857_cfg_setup(rs4857_cfg_t *cfg)
RS485 7 configuration object setup function.
rs4857_return_value_t
rs4857_return_value_t
RS485 7 Click return value data.
Definition: rs4857.h:140
rs4857_termination_ab_enable
void rs4857_termination_ab_enable(rs4857_t *ctx)
RS485 7 A-B termination enable function.