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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_uart.h"
51 
73 #define RS4857_TX_DRV_BUFFER_SIZE 100
74 #define RS4857_RX_DRV_BUFFER_SIZE 300
75  // rs4857_cmd
77 
92 #define RS4857_MAP_MIKROBUS( cfg, mikrobus ) \
93  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
94  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
95  cfg.de = MIKROBUS( mikrobus, MIKROBUS_AN ); \
96  cfg.re = MIKROBUS( mikrobus, MIKROBUS_RST ); \
97  cfg.ret = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
98  cfg.tet = MIKROBUS( mikrobus, MIKROBUS_INT )
99  // rs4857_map // rs4857
102 
107 typedef struct
108 {
109  // Output pins
110  digital_out_t de;
111  digital_out_t re;
112  digital_out_t ret;
113  digital_out_t tet;
115  // Modules
116  uart_t uart;
118  // Buffers
119  char uart_rx_buffer[ RS4857_RX_DRV_BUFFER_SIZE ];
120  char uart_tx_buffer[ RS4857_TX_DRV_BUFFER_SIZE ];
122 } rs4857_t;
123 
128 typedef struct
129 {
130  // Communication gpio pins
131  pin_name_t rx_pin;
132  pin_name_t tx_pin;
134  // Additional gpio pins
135  pin_name_t de;
136  pin_name_t re;
137  pin_name_t ret;
138  pin_name_t tet;
140  // Static variable
141  uint32_t baud_rate;
143  uart_data_bits_t data_bit;
144  uart_parity_t parity_bit;
145  uart_stop_bits_t stop_bit;
147 } rs4857_cfg_t;
148 
153 typedef enum
154 {
156  RS4857_ERROR = -1
157 
159 
176 
190 err_t rs4857_init ( rs4857_t *ctx, rs4857_cfg_t *cfg );
191 
204 err_t rs4857_generic_write ( rs4857_t *ctx, char *data_in, uint16_t len );
205 
218 err_t rs4857_generic_read ( rs4857_t *ctx, char *data_out, uint16_t len );
219 
231 
243 
255 
267 
279 
291 
303 
315 
316 #ifdef __cplusplus
317 }
318 #endif
319 #endif // RS4857_H
320  // rs4857
322 
323 // ------------------------------------------------------------------------ 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:145
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:116
rs4857_cfg_t::de
pin_name_t de
Definition: rs4857.h:135
rs4857_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs4857.h:144
RS4857_ERROR
@ RS4857_ERROR
Definition: rs4857.h:156
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:143
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:110
rs4857_cfg_t::uart_blocking
bool uart_blocking
Definition: rs4857.h:142
rs4857_t::tet
digital_out_t tet
Definition: rs4857.h:113
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:108
RS4857_OK
@ RS4857_OK
Definition: rs4857.h:155
RS4857_RX_DRV_BUFFER_SIZE
#define RS4857_RX_DRV_BUFFER_SIZE
Definition: rs4857.h:74
rs4857_t::re
digital_out_t re
Definition: rs4857.h:111
rs4857_cfg_t::ret
pin_name_t ret
Definition: rs4857.h:137
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:73
rs4857_t::ret
digital_out_t ret
Definition: rs4857.h:112
rs4857_cfg_t
RS485 7 Click configuration object.
Definition: rs4857.h:129
rs4857_cfg_t::tet
pin_name_t tet
Definition: rs4857.h:138
rs4857_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs4857.h:131
rs4857_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs4857.h:132
rs4857_cfg_t::baud_rate
uint32_t baud_rate
Definition: rs4857.h:141
rs4857_cfg_t::re
pin_name_t re
Definition: rs4857.h:136
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:154
rs4857_termination_ab_enable
void rs4857_termination_ab_enable(rs4857_t *ctx)
RS485 7 A-B termination enable function.