lin  2.0.0.0
lin.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * 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 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define LIN_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57  cfg.wk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
58  cfg.inh = MIKROBUS( mikrobus, MIKROBUS_INT );
59 
65 #define LIN_RETVAL uint8_t
66 
67 #define LIN_OK 0x00
68 #define LIN_INIT_ERROR 0xFF
69 
75 #define LIN_OK 0x00
76 #define LIN_FUNCTION_ERROR 0xEE
77 #define LIN_INIT_ERROR 0xFF
78 
84 #define LIN_PIN_STATE_LOW 0
85 #define LIN_PIN_STATE_HIGH 1
86  // End group macro
89 // --------------------------------------------------------------- PUBLIC TYPES
95 typedef uart_data_t lin_data_t;
96 
100 typedef struct
101 {
102  // Output pins
103 
104  digital_out_t en;
105  digital_out_t wk;
106  digital_out_t inh;
107 
108  // Modules
109 
110  uart_t uart;
111 
112 } lin_t;
113 
117 typedef struct
118 {
119  // Communication gpio pins
120 
121  pin_name_t rx_pin;
122  pin_name_t tx_pin;
123 
124  // Additional gpio pins
125 
126  pin_name_t en;
127  pin_name_t wk;
128  pin_name_t inh;
129 
130  // static variable
131 
132  hal_uart_baudrate_t baud_rate; // Clock speed.
133  hal_uart_data_bits_t data_bit; // Data bits.
134  hal_uart_parity_bit_t parity_bit; // Parity bit.
135  hal_uart_stop_bits_t stop_bit; // Stop bits.
136 
137 } lin_cfg_t;
138  // End types group
140 
141 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
142 
148 #ifdef __cplusplus
149 extern "C"{
150 #endif
151 
160 void lin_cfg_setup ( lin_cfg_t *cfg );
161 
169 LIN_RETVAL lin_init ( lin_t *ctx, lin_cfg_t *cfg );
170 
180 void lin_generic_multi_write ( lin_t *ctx, lin_data_t *data_buf, uart_length_t len );
181 
191 void lin_generic_multi_read ( lin_t *ctx, lin_data_t *data_buf, uart_length_t len );
192 
193 
203 
212 void lin_generic_single_write ( lin_t *ctx, lin_data_t tx_data );
213 
224 uint8_t lin_enable_pin_set( lin_t *ctx, uint8_t state );
225 
236 uint8_t lin_inhibit_pin_set( lin_t *ctx, uint8_t state );
237 
248 uint8_t lin_wake_pin_set( lin_t *ctx, uint8_t state );
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 #endif // _LIN_H_
254  // End public_function group
257 
258 // ------------------------------------------------------------------------- END
lin_generic_single_read
lin_data_t lin_generic_single_read(lin_t *ctx)
Generic single read function.
lin_init
LIN_RETVAL lin_init(lin_t *ctx, lin_cfg_t *cfg)
Initialization function.
lin_generic_single_write
void lin_generic_single_write(lin_t *ctx, lin_data_t tx_data)
Generic single write function.
lin_cfg_t::stop_bit
hal_uart_stop_bits_t stop_bit
Definition: lin.h:135
lin_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lin.h:122
LIN_RETVAL
#define LIN_RETVAL
Definition: lin.h:65
lin_t::uart
uart_t uart
Definition: lin.h:110
lin_cfg_t::data_bit
hal_uart_data_bits_t data_bit
Definition: lin.h:133
lin_generic_multi_read
void lin_generic_multi_read(lin_t *ctx, lin_data_t *data_buf, uart_length_t len)
Generic multi read function.
lin_cfg_t::inh
pin_name_t inh
Definition: lin.h:128
lin_generic_multi_write
void lin_generic_multi_write(lin_t *ctx, lin_data_t *data_buf, uart_length_t len)
Generic multi write function.
lin_t
Click ctx object definition.
Definition: lin.h:100
lin_cfg_t::wk
pin_name_t wk
Definition: lin.h:127
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:126
lin_t::inh
digital_out_t inh
Definition: lin.h:106
lin_enable_pin_set
uint8_t lin_enable_pin_set(lin_t *ctx, uint8_t state)
Sets state of pin.
lin_inhibit_pin_set
uint8_t lin_inhibit_pin_set(lin_t *ctx, uint8_t state)
Sets state of pin.
lin_cfg_t::rx_pin
pin_name_t rx_pin
Definition: lin.h:121
lin_cfg_t::baud_rate
hal_uart_baudrate_t baud_rate
Definition: lin.h:132
lin_data_t
uart_data_t lin_data_t
Definition: lin.h:95
lin_cfg_t
Click configuration structure definition.
Definition: lin.h:117
lin_t::en
digital_out_t en
Definition: lin.h:104
lin_cfg_t::parity_bit
hal_uart_parity_bit_t parity_bit
Definition: lin.h:134
lin_t::wk
digital_out_t wk
Definition: lin.h:105
lin_wake_pin_set
uint8_t lin_wake_pin_set(lin_t *ctx, uint8_t state)
Sets state of pin.