lin 2.0.0.0
lin.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 LIN_H
36#define LIN_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 LIN_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70 cfg.wk = MIKROBUS( mikrobus, MIKROBUS_PWM );
77#define LIN_RETVAL uint8_t
78
79#define LIN_OK 0x00
80#define LIN_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 en;
104 digital_out_t wk;
105
106 // Modules
107
108 uart_t uart;
109
110 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
111 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
112
113} lin_t;
114
118typedef struct
119{
120 // Communication gpio pins
121
122 pin_name_t rx_pin;
123 pin_name_t tx_pin;
124
125 // Additional gpio pins
126
127 pin_name_t en;
128 pin_name_t wk;
129
130 // static variable
131
132 uint32_t baud_rate; // Clock speed.
134 uart_data_bits_t data_bit; // Data bits.
135 uart_parity_t parity_bit; // Parity bit.
136 uart_stop_bits_t stop_bit; // Stop bits.
137
138} lin_cfg_t;
139
143typedef uint8_t lin_error_t;
144
145 // End types group
146// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
147
153#ifdef __cplusplus
154extern "C"{
155#endif
156
166
176
184void lin_generic_write ( lin_t *ctx, char *data_buf, uint16_t len );
185
195int32_t lin_generic_read ( lin_t *ctx, char *data_buf, uint16_t max_len );
196
203void lin_set_enable ( lin_t *ctx, uint8_t state );
204
211void lin_set_wake_up ( lin_t *ctx, uint8_t state );
212
213#ifdef __cplusplus
214}
215#endif
216#endif // _LIN_H_
217
218 // End public_function group
220
221// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition lin.h:87
#define LIN_RETVAL
Definition lin.h:77
void lin_set_wake_up(lin_t *ctx, uint8_t state)
Set wake up pin state.
void lin_cfg_setup(lin_cfg_t *cfg)
Config Object Initialization function.
void lin_generic_write(lin_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void lin_set_enable(lin_t *ctx, uint8_t state)
Set enable pin state.
LIN_RETVAL lin_init(lin_t *ctx, lin_cfg_t *cfg)
Initialization function.
int32_t lin_generic_read(lin_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
uint8_t lin_error_t
Error type.
Definition lin.h:143
Click configuration structure definition.
Definition lin.h:119
uint32_t baud_rate
Definition lin.h:132
pin_name_t wk
Definition lin.h:128
bool uart_blocking
Definition lin.h:133
uart_data_bits_t data_bit
Definition lin.h:134
pin_name_t tx_pin
Definition lin.h:123
pin_name_t rx_pin
Definition lin.h:122
uart_stop_bits_t stop_bit
Definition lin.h:136
pin_name_t en
Definition lin.h:127
uart_parity_t parity_bit
Definition lin.h:135
Click ctx object definition.
Definition lin.h:100
uart_t uart
Definition lin.h:108
digital_out_t wk
Definition lin.h:104
digital_out_t en
Definition lin.h:103