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 );
71 
77 #define LIN_RETVAL uint8_t
78 
79 #define LIN_OK 0x00
80 #define LIN_INIT_ERROR 0xFF
81 
87 #define DRV_RX_BUFFER_SIZE 500
88  // End group macro
91 // --------------------------------------------------------------- PUBLIC TYPES
99 typedef 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 
118 typedef 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 
143 typedef uint8_t lin_error_t;
144  // End types group
146 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
147 
153 #ifdef __cplusplus
154 extern "C"{
155 #endif
156 
165 void lin_cfg_setup ( lin_cfg_t *cfg );
166 
176 
184 void lin_generic_write ( lin_t *ctx, char *data_buf, uint16_t len );
185 
195 int32_t lin_generic_read ( lin_t *ctx, char *data_buf, uint16_t max_len );
196 
203 void lin_set_enable ( lin_t *ctx, uint8_t state );
204 
211 void lin_set_wake_up ( lin_t *ctx, uint8_t state );
212 
213 #ifdef __cplusplus
214 }
215 #endif
216 #endif // _LIN_H_
217  // End public_function group
220 
221 // ------------------------------------------------------------------------- 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:87
lin_error_t
uint8_t lin_error_t
Error type.
Definition: lin.h:143
lin_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lin.h:123
LIN_RETVAL
#define LIN_RETVAL
Definition: lin.h:77
lin_cfg_t::uart_blocking
bool uart_blocking
Definition: lin.h:133
lin_t::uart
uart_t uart
Definition: lin.h:108
lin_cfg_t::baud_rate
uint32_t baud_rate
Definition: lin.h:132
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:100
lin_cfg_t::wk
pin_name_t wk
Definition: lin.h:128
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:127
lin_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lin.h:134
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:122
lin_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lin.h:136
lin_cfg_t
Click configuration structure definition.
Definition: lin.h:119
lin_t::en
digital_out_t en
Definition: lin.h:103
lin_t::wk
digital_out_t wk
Definition: lin.h:104
lin_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lin.h:135