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 "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_uart.h"
47 
69 #define RS4857_TX_DRV_BUFFER_SIZE 100
70 #define RS4857_RX_DRV_BUFFER_SIZE 300
71  // rs4857_cmd
73 
88 #define RS4857_MAP_MIKROBUS( cfg, mikrobus ) \
89  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
90  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
91  cfg.de = MIKROBUS( mikrobus, MIKROBUS_AN ); \
92  cfg.re = MIKROBUS( mikrobus, MIKROBUS_RST ); \
93  cfg.ret = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
94  cfg.tet = MIKROBUS( mikrobus, MIKROBUS_INT )
95  // rs4857_map // rs4857
98 
103 typedef struct
104 {
105  // Output pins
106  digital_out_t de;
107  digital_out_t re;
108  digital_out_t ret;
109  digital_out_t tet;
111  // Modules
112  uart_t uart;
114  // Buffers
115  char uart_rx_buffer[ RS4857_RX_DRV_BUFFER_SIZE ];
116  char uart_tx_buffer[ RS4857_TX_DRV_BUFFER_SIZE ];
118 } rs4857_t;
119 
124 typedef struct
125 {
126  // Communication gpio pins
127  pin_name_t rx_pin;
128  pin_name_t tx_pin;
130  // Additional gpio pins
131  pin_name_t de;
132  pin_name_t re;
133  pin_name_t ret;
134  pin_name_t tet;
136  // Static variable
137  uint32_t baud_rate;
139  uart_data_bits_t data_bit;
140  uart_parity_t parity_bit;
141  uart_stop_bits_t stop_bit;
143 } rs4857_cfg_t;
144 
149 typedef enum
150 {
152  RS4857_ERROR = -1
153 
155 
172 
186 err_t rs4857_init ( rs4857_t *ctx, rs4857_cfg_t *cfg );
187 
200 err_t rs4857_generic_write ( rs4857_t *ctx, char *data_in, uint16_t len );
201 
214 err_t rs4857_generic_read ( rs4857_t *ctx, char *data_out, uint16_t len );
215 
227 
239 
251 
263 
275 
287 
299 
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 #endif // RS4857_H
316  // rs4857
318 
319 // ------------------------------------------------------------------------ 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:141
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:112
rs4857_cfg_t::de
pin_name_t de
Definition: rs4857.h:131
rs4857_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs4857.h:140
RS4857_ERROR
@ RS4857_ERROR
Definition: rs4857.h:152
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:139
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:106
rs4857_cfg_t::uart_blocking
bool uart_blocking
Definition: rs4857.h:138
rs4857_t::tet
digital_out_t tet
Definition: rs4857.h:109
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:104
RS4857_OK
@ RS4857_OK
Definition: rs4857.h:151
RS4857_RX_DRV_BUFFER_SIZE
#define RS4857_RX_DRV_BUFFER_SIZE
Definition: rs4857.h:70
rs4857_t::re
digital_out_t re
Definition: rs4857.h:107
rs4857_cfg_t::ret
pin_name_t ret
Definition: rs4857.h:133
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:69
rs4857_t::ret
digital_out_t ret
Definition: rs4857.h:108
rs4857_cfg_t
RS485 7 Click configuration object.
Definition: rs4857.h:125
rs4857_cfg_t::tet
pin_name_t tet
Definition: rs4857.h:134
rs4857_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs4857.h:127
rs4857_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs4857.h:128
rs4857_cfg_t::baud_rate
uint32_t baud_rate
Definition: rs4857.h:137
rs4857_cfg_t::re
pin_name_t re
Definition: rs4857.h:132
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:150
rs4857_termination_ab_enable
void rs4857_termination_ab_enable(rs4857_t *ctx)
RS485 7 A-B termination enable function.