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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define LIN_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
56  cfg.wk = MIKROBUS( mikrobus, MIKROBUS_PWM );
57 
63 #define LIN_RETVAL uint8_t
64 
65 #define LIN_OK 0x00
66 #define LIN_INIT_ERROR 0xFF
67 
73 #define DRV_RX_BUFFER_SIZE 500
74  // End group macro
77 // --------------------------------------------------------------- PUBLIC TYPES
85 typedef struct
86 {
87  // Output pins
88 
89  digital_out_t en;
90  digital_out_t wk;
91 
92  // Modules
93 
94  uart_t uart;
95 
96  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
97  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
98 
99 } lin_t;
100 
104 typedef struct
105 {
106  // Communication gpio pins
107 
108  pin_name_t rx_pin;
109  pin_name_t tx_pin;
110 
111  // Additional gpio pins
112 
113  pin_name_t en;
114  pin_name_t wk;
115 
116  // static variable
117 
118  uint32_t baud_rate; // Clock speed.
120  uart_data_bits_t data_bit; // Data bits.
121  uart_parity_t parity_bit; // Parity bit.
122  uart_stop_bits_t stop_bit; // Stop bits.
123 
124 } lin_cfg_t;
125 
129 typedef uint8_t lin_error_t;
130  // End types group
132 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
133 
139 #ifdef __cplusplus
140 extern "C"{
141 #endif
142 
151 void lin_cfg_setup ( lin_cfg_t *cfg );
152 
162 
170 void lin_generic_write ( lin_t *ctx, char *data_buf, uint16_t len );
171 
181 int32_t lin_generic_read ( lin_t *ctx, char *data_buf, uint16_t max_len );
182 
189 void lin_set_enable ( lin_t *ctx, uint8_t state );
190 
197 void lin_set_wake_up ( lin_t *ctx, uint8_t state );
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 #endif // _LIN_H_
203  // End public_function group
206 
207 // ------------------------------------------------------------------------- END
lin_init
LIN_RETVAL lin_init(lin_t *ctx, lin_cfg_t *cfg)
Initialization function.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: lin.h:73
lin_error_t
uint8_t lin_error_t
Error type.
Definition: lin.h:129
lin_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lin.h:109
LIN_RETVAL
#define LIN_RETVAL
Definition: lin.h:63
lin_cfg_t::uart_blocking
bool uart_blocking
Definition: lin.h:119
lin_t::uart
uart_t uart
Definition: lin.h:94
lin_cfg_t::baud_rate
uint32_t baud_rate
Definition: lin.h:118
lin_generic_write
void lin_generic_write(lin_t *ctx, char *data_buf, uint16_t len)
Generic write function.
lin_set_wake_up
void lin_set_wake_up(lin_t *ctx, uint8_t state)
Set wake up pin state.
lin_set_enable
void lin_set_enable(lin_t *ctx, uint8_t state)
Set enable pin state.
lin_t
Click ctx object definition.
Definition: lin.h:86
lin_cfg_t::wk
pin_name_t wk
Definition: lin.h:114
lin_cfg_setup
void lin_cfg_setup(lin_cfg_t *cfg)
Config Object Initialization function.
lin_cfg_t::en
pin_name_t en
Definition: lin.h:113
lin_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lin.h:120
lin_generic_read
int32_t lin_generic_read(lin_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
lin_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lin.h:108
lin_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lin.h:122
lin_cfg_t
Click configuration structure definition.
Definition: lin.h:105
lin_t::en
digital_out_t en
Definition: lin.h:89
lin_t::wk
digital_out_t wk
Definition: lin.h:90
lin_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lin.h:121