HPM SDK
HPMicro Software Development Kit
hpm_lin_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_LIN_DRV_H
9 #define HPM_LIN_DRV_H
10 
11 #include <math.h>
12 #include "hpm_common.h"
13 #include "hpm_lin_regs.h"
14 #include "hpm_soc_feature.h"
15 
17 #define LIN_ID_DATA_LEN_SHIFT 4U
18 #define LIN_ID_DATA_LEN_MASK 0x30U
19 #define LIN_ID_DATA_LEN_GET(x) (((uint8_t)(x) & LIN_ID_DATA_LEN_MASK) >> LIN_ID_DATA_LEN_SHIFT)
20 
31 typedef enum {
37 
41 typedef enum {
47 
51 typedef enum {
57 
58 typedef struct {
59  uint32_t src_freq_in_hz;
60  uint32_t baudrate;
61 } lin_timing_t;
62 
66 typedef struct {
67  uint8_t id;
68  uint8_t *data_buff;
70  uint8_t data_length;
72  bool transmit;
73  /* bool start; */
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
86 static inline uint8_t lin_get_status(LIN_Type *ptr)
87 {
88  return ptr->STATE;
89 }
90 
96 static inline void lin_reset_interrupt(LIN_Type *ptr)
97 {
99 }
100 
106 static inline void lin_reset_error(LIN_Type *ptr)
107 {
109 }
110 
116 static inline void lin_wakeup(LIN_Type *ptr)
117 {
119 }
120 
126 static inline void lin_sleep(LIN_Type *ptr)
127 {
129 }
130 
136 static inline void lin_slave_stop(LIN_Type *ptr)
137 {
139 }
140 
146 static inline void lin_slave_ack(LIN_Type *ptr)
147 {
149 }
150 
158 {
159  ptr->TV |= LIN_TV_BUS_INACTIVITY_TIME_SET(time);
160 }
161 
169 {
170  ptr->TV |= LIN_TV_WUP_REPEAT_TIME_SET(time);
171 }
172 
179 static inline void lin_set_mode(LIN_Type *ptr, bool master)
180 {
181  if (master) {
182  ptr->TV |= LIN_TV_MASTER_MODE_MASK;
183  } else {
184  ptr->TV &= ~LIN_TV_MASTER_MODE_MASK;
185  }
186 }
187 
195 static inline uint8_t lin_get_data_byte(LIN_Type *ptr, uint8_t index)
196 {
197  return ptr->DATABYTE[index];
198 }
199 
207 static inline void lin_write_data_byte(LIN_Type *ptr, uint8_t index, uint8_t data)
208 {
209  ptr->DATABYTE[index] = data;
210 }
211 
218 static inline bool lin_is_active(LIN_Type *ptr)
219 {
220  return ((ptr->STATE & LIN_STATE_LIN_ACTIVE_MASK) == LIN_STATE_LIN_ACTIVE_MASK) ? true : false;
221 }
222 
229 static inline bool lin_is_complete(LIN_Type *ptr)
230 {
231  return ((ptr->STATE & LIN_STATE_COMPLETE_MASK) == LIN_STATE_COMPLETE_MASK) ? true : false;
232 }
233 
240 static inline uint8_t lin_get_id(LIN_Type *ptr)
241 {
242  return ptr->ID;
243 }
244 
253 
261 hpm_stat_t lin_slave_configure_timing(LIN_Type *ptr, uint32_t src_freq_in_hz);
262 
270 
280 
289 uint8_t lin_get_data_length(LIN_Type *ptr);
290 
300 
310 
320 
330 
335 #ifdef __cplusplus
336 }
337 #endif
338 
339 #endif /* HPM_LIN_DRV_H */
340 
uint32_t hpm_stat_t
Definition: hpm_common.h:126
lin_id_data_length_t
data length in ID bit4 and bit5
Definition: hpm_lin_drv.h:31
static void lin_slave_ack(LIN_Type *ptr)
lin slave ack
Definition: hpm_lin_drv.h:146
static void lin_wakeup(LIN_Type *ptr)
lin wakeup
Definition: hpm_lin_drv.h:116
static void lin_set_mode(LIN_Type *ptr, bool master)
lin set mode
Definition: hpm_lin_drv.h:179
static void lin_reset_error(LIN_Type *ptr)
lin reset error
Definition: hpm_lin_drv.h:106
void lin_slave_transfer(LIN_Type *ptr, lin_trans_config_t *config)
lin transfer on slave mode
Definition: hpm_lin_drv.c:232
static void lin_slave_set_bus_inactivity_time(LIN_Type *ptr, lin_bus_inactivity_time_t time)
lin slave set bus inactivity time
Definition: hpm_lin_drv.h:157
uint8_t lin_get_data_length(LIN_Type *ptr)
get data length
Definition: hpm_lin_drv.c:86
hpm_stat_t lin_master_sent(LIN_Type *ptr, lin_trans_config_t *config)
lin send data on master mode
Definition: hpm_lin_drv.c:127
static uint8_t lin_get_data_byte(LIN_Type *ptr, uint8_t index)
lin get data value in byte
Definition: hpm_lin_drv.h:195
static bool lin_is_complete(LIN_Type *ptr)
lin complete status
Definition: hpm_lin_drv.h:229
static void lin_write_data_byte(LIN_Type *ptr, uint8_t index, uint8_t data)
lin write data value in byte
Definition: hpm_lin_drv.h:207
static void lin_reset_interrupt(LIN_Type *ptr)
lin reset interrupt
Definition: hpm_lin_drv.h:96
static uint8_t lin_get_status(LIN_Type *ptr)
lin get STATE register value
Definition: hpm_lin_drv.h:86
hpm_stat_t lin_slave_configure_timing(LIN_Type *ptr, uint32_t src_freq_in_hz)
lin config timing on slave mode
Definition: hpm_lin_drv.c:43
lin_wakeup_repeat_time_t
wakeup repeat time
Definition: hpm_lin_drv.h:51
static bool lin_is_active(LIN_Type *ptr)
lin active status
Definition: hpm_lin_drv.h:218
static void lin_sleep(LIN_Type *ptr)
lin sleep
Definition: hpm_lin_drv.h:126
static uint8_t lin_get_id(LIN_Type *ptr)
lin get ID
Definition: hpm_lin_drv.h:240
static void lin_slave_stop(LIN_Type *ptr)
lin slave stop
Definition: hpm_lin_drv.h:136
hpm_stat_t lin_slave_receive(LIN_Type *ptr, lin_trans_config_t *config)
lin receive data on slave mode
Definition: hpm_lin_drv.c:308
lin_bus_inactivity_time_t
bus inactivity tome to go to sleep
Definition: hpm_lin_drv.h:41
hpm_stat_t lin_master_receive(LIN_Type *ptr, lin_trans_config_t *config)
lin receive data on master mode
Definition: hpm_lin_drv.c:179
void lin_master_transfer(LIN_Type *ptr, lin_trans_config_t *config)
lin transfer on master mode
Definition: hpm_lin_drv.c:97
hpm_stat_t lin_slave_sent(LIN_Type *ptr, lin_trans_config_t *config)
lin send data on slave mode
Definition: hpm_lin_drv.c:257
static void lin_slave_set_wakeup_repeat_time(LIN_Type *ptr, lin_wakeup_repeat_time_t time)
lin slave set wakeup repeat time
Definition: hpm_lin_drv.h:168
hpm_stat_t lin_master_configure_timing(LIN_Type *ptr, lin_timing_t *timing)
lin configure timing on master mode
Definition: hpm_lin_drv.c:12
@ id_data_length_2bytes
Definition: hpm_lin_drv.h:32
@ id_data_length_4bytes
Definition: hpm_lin_drv.h:34
@ id_data_length_8bytes
Definition: hpm_lin_drv.h:35
@ id_data_length_2bytes_2
Definition: hpm_lin_drv.h:33
@ wakeup_repeat_time_240ms
Definition: hpm_lin_drv.h:55
@ wakeup_repeat_time_200ms
Definition: hpm_lin_drv.h:53
@ wakeup_repeat_time_180ms
Definition: hpm_lin_drv.h:52
@ wakeup_repeat_time_220ms
Definition: hpm_lin_drv.h:54
@ bus_inactivity_time_10s
Definition: hpm_lin_drv.h:45
@ bus_inactivity_time_6s
Definition: hpm_lin_drv.h:43
@ bus_inactivity_time_4s
Definition: hpm_lin_drv.h:42
@ bus_inactivity_time_8s
Definition: hpm_lin_drv.h:44
#define LIN_CONTROL_DATA_ACK_MASK
Definition: hpm_lin_regs.h:72
#define LIN_CONTROL_STOP_MASK
Definition: hpm_lin_regs.h:42
#define LIN_STATE_LIN_ACTIVE_MASK
Definition: hpm_lin_regs.h:123
#define LIN_CONTROL_RESET_ERROR_MASK
Definition: hpm_lin_regs.h:92
#define LIN_CONTROL_SLEEP_MASK
Definition: hpm_lin_regs.h:52
#define LIN_CONTROL_WAKEUP_REQ_MASK
Definition: hpm_lin_regs.h:102
#define LIN_TV_MASTER_MODE_MASK
Definition: hpm_lin_regs.h:317
#define LIN_STATE_COMPLETE_MASK
Definition: hpm_lin_regs.h:186
#define LIN_CONTROL_RESET_INT_MASK
Definition: hpm_lin_regs.h:82
#define LIN_TV_BUS_INACTIVITY_TIME_SET(x)
Definition: hpm_lin_regs.h:329
#define LIN_TV_WUP_REPEAT_TIME_SET(x)
Definition: hpm_lin_regs.h:339
Definition: hpm_lin_regs.h:12
__RW uint32_t DATABYTE[8]
Definition: hpm_lin_regs.h:13
__RW uint32_t ID
Definition: hpm_lin_regs.h:20
__R uint32_t STATE
Definition: hpm_lin_regs.h:15
__RW uint32_t CONTROL
Definition: hpm_lin_regs.h:14
__RW uint32_t TV
Definition: hpm_lin_regs.h:21
Definition: hpm_lin_drv.h:58
uint32_t src_freq_in_hz
Definition: hpm_lin_drv.h:59
uint32_t baudrate
Definition: hpm_lin_drv.h:60
LIN config.
Definition: hpm_lin_drv.h:66
uint8_t id
Definition: hpm_lin_drv.h:67
bool enhanced_checksum
Definition: hpm_lin_drv.h:71
bool data_length_from_id
Definition: hpm_lin_drv.h:69
uint8_t * data_buff
Definition: hpm_lin_drv.h:68
bool transmit
Definition: hpm_lin_drv.h:72
uint8_t data_length
Definition: hpm_lin_drv.h:70