rs232 2.0.0.0
rs232.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 RS232_H
36#define RS232_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 RS232_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define RS232_RETVAL uint8_t
78
79#define RS232_OK 0x00
80#define RS232_INIT_ERROR 0xFF
87#define DRV_RX_BUFFER_SIZE 500
90 // End group macro
91// --------------------------------------------------------------- PUBLIC TYPES
99typedef struct
100{
101 // Output pins
102
103 digital_out_t rts;
104
105 // Input pins
106
107 digital_in_t cts;
108
109 // Modules
110
111 uart_t uart;
112
113 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
114 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
115
116} rs232_t;
117
121typedef struct
122{
123 // Communication gpio pins
124
125 pin_name_t rx_pin;
126 pin_name_t tx_pin;
127
128 // Additional gpio pins
129
130 pin_name_t rts;
131 pin_name_t cts;
132
133 // static variable
134
135 uint32_t baud_rate; // Clock speed.
137 uart_data_bits_t data_bit; // Data bits.
138 uart_parity_t parity_bit; // Parity bit.
139 uart_stop_bits_t stop_bit; // Stop bits.
140
142
146typedef uint8_t rs232_error_t;
147
148 // End types group
149// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
150
156#ifdef __cplusplus
157extern "C"{
158#endif
159
169
178
185void rs232_generic_write ( rs232_t *ctx, char *data_buf, uint16_t len );
186
194int32_t rs232_generic_read ( rs232_t *ctx, char *data_buf, uint16_t max_len );
195
203
210void rs232_set_rts_state ( rs232_t *ctx, uint8_t state );
211
212#ifdef __cplusplus
213}
214#endif
215#endif // _RS232_H_
216
217 // End public_function group
219
220// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition rs232.h:87
#define RS232_RETVAL
Definition rs232.h:77
void rs232_cfg_setup(rs232_cfg_t *cfg)
Config Object Initialization function.
void rs232_set_rts_state(rs232_t *ctx, uint8_t state)
Set RTS pin state.
uint8_t rs232_get_cts_state(rs232_t *ctx)
Get CTS pin state (Clear to send)
int32_t rs232_generic_read(rs232_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void rs232_generic_write(rs232_t *ctx, char *data_buf, uint16_t len)
Generic write function.
RS232_RETVAL rs232_init(rs232_t *ctx, rs232_cfg_t *cfg)
Initialization function.
uint8_t rs232_error_t
Error type.
Definition rs232.h:146
Click configuration structure definition.
Definition rs232.h:122
pin_name_t rts
Definition rs232.h:130
uint32_t baud_rate
Definition rs232.h:135
pin_name_t cts
Definition rs232.h:131
bool uart_blocking
Definition rs232.h:136
uart_data_bits_t data_bit
Definition rs232.h:137
pin_name_t tx_pin
Definition rs232.h:126
pin_name_t rx_pin
Definition rs232.h:125
uart_stop_bits_t stop_bit
Definition rs232.h:139
uart_parity_t parity_bit
Definition rs232.h:138
Click ctx object definition.
Definition rs232.h:100
digital_out_t rts
Definition rs232.h:103
uart_t uart
Definition rs232.h:111
digital_in_t cts
Definition rs232.h:107