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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define LIN_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
64  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
65  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
66  cfg.wk = MIKROBUS( mikrobus, MIKROBUS_PWM );
67 
73 #define LIN_RETVAL uint8_t
74 
75 #define LIN_OK 0x00
76 #define LIN_INIT_ERROR 0xFF
77 
83 #define DRV_RX_BUFFER_SIZE 500
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
95 typedef struct
96 {
97  // Output pins
98 
99  digital_out_t en;
100  digital_out_t wk;
101 
102  // Modules
103 
104  uart_t uart;
105 
106  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
107  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
108 
109 } lin_t;
110 
114 typedef struct
115 {
116  // Communication gpio pins
117 
118  pin_name_t rx_pin;
119  pin_name_t tx_pin;
120 
121  // Additional gpio pins
122 
123  pin_name_t en;
124  pin_name_t wk;
125 
126  // static variable
127 
128  uint32_t baud_rate; // Clock speed.
130  uart_data_bits_t data_bit; // Data bits.
131  uart_parity_t parity_bit; // Parity bit.
132  uart_stop_bits_t stop_bit; // Stop bits.
133 
134 } lin_cfg_t;
135 
139 typedef uint8_t lin_error_t;
140  // End types group
142 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143 
149 #ifdef __cplusplus
150 extern "C"{
151 #endif
152 
161 void lin_cfg_setup ( lin_cfg_t *cfg );
162 
172 
180 void lin_generic_write ( lin_t *ctx, char *data_buf, uint16_t len );
181 
191 int32_t lin_generic_read ( lin_t *ctx, char *data_buf, uint16_t max_len );
192 
199 void lin_set_enable ( lin_t *ctx, uint8_t state );
200 
207 void lin_set_wake_up ( lin_t *ctx, uint8_t state );
208 
209 #ifdef __cplusplus
210 }
211 #endif
212 #endif // _LIN_H_
213  // End public_function group
216 
217 // ------------------------------------------------------------------------- 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:83
lin_error_t
uint8_t lin_error_t
Error type.
Definition: lin.h:139
lin_cfg_t::tx_pin
pin_name_t tx_pin
Definition: lin.h:119
LIN_RETVAL
#define LIN_RETVAL
Definition: lin.h:73
lin_cfg_t::uart_blocking
bool uart_blocking
Definition: lin.h:129
lin_t::uart
uart_t uart
Definition: lin.h:104
lin_cfg_t::baud_rate
uint32_t baud_rate
Definition: lin.h:128
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:96
lin_cfg_t::wk
pin_name_t wk
Definition: lin.h:124
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:123
lin_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: lin.h:130
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:118
lin_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: lin.h:132
lin_cfg_t
Click configuration structure definition.
Definition: lin.h:115
lin_t::en
digital_out_t en
Definition: lin.h:99
lin_t::wk
digital_out_t wk
Definition: lin.h:100
lin_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: lin.h:131