HPM SDK
HPMicro Software Development Kit
hpm_linv2_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_LINV2_DRV_H
9 #define HPM_LINV2_DRV_H
10 
11 #include <math.h>
12 #include "hpm_common.h"
13 #include "hpm_linv2_regs.h"
14 #include "hpm_soc_feature.h"
15 
24 #define LIN_ID_DATA_LEN_SHIFT 4U
25 #define LIN_ID_DATA_LEN_MASK 0x30U
26 #define LIN_ID_DATA_LEN_GET(x) (((uint8_t)(x) & LIN_ID_DATA_LEN_MASK) >> LIN_ID_DATA_LEN_SHIFT)
27 
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;
69  bool data_length_from_id;
70  uint8_t data_length;
71  bool enhanced_checksum;
72  bool transmit;
73  /* bool start; */
75 
76 #ifdef __cplusplus
77 extern "C" {
78 #endif
79 
86 static inline uint32_t lin_get_control_and_status(LINV2_Type *ptr)
87 {
88  return ptr->CONTROL_STATUS;
89 }
90 
96 static inline void lin_reset_interrupt(LINV2_Type *ptr)
97 {
99 }
100 
106 static inline void lin_reset_error(LINV2_Type *ptr)
107 {
109 }
110 
116 static inline void lin_wakeup(LINV2_Type *ptr)
117 {
119 }
120 
126 static inline void lin_sleep(LINV2_Type *ptr)
127 {
129 }
130 
136 static inline void lin_slave_stop(LINV2_Type *ptr)
137 {
139 }
140 
146 static inline void lin_slave_ack(LINV2_Type *ptr)
147 {
149 }
150 
158 {
161 }
162 
170 {
173 }
174 
181 static inline void lin_set_mode(LINV2_Type *ptr, bool master)
182 {
183  if (master) {
185  } else {
187  }
188 }
189 
196 static inline void lin_set_checksum_mode(LINV2_Type *ptr, bool enhance_checksum)
197 {
198  if (enhance_checksum) {
200  } else {
202  }
203 }
204 
212 static inline uint8_t lin_get_data_byte(LINV2_Type *ptr, uint8_t index)
213 {
214  return ptr->DATA_BYTE[index];
215 }
216 
224 static inline void lin_write_data_byte(LINV2_Type *ptr, uint8_t index, uint8_t data)
225 {
226  ptr->DATA_BYTE[index] = data;
227 }
228 
235 static inline uint8_t lin_get_id(LINV2_Type *ptr)
236 {
237  return (uint8_t)LINV2_DATA_LEN_ID_ID_GET(ptr->DATA_LEN_ID);
238 }
239 
246 static inline uint8_t lin_get_checksum(LINV2_Type *ptr)
247 {
248  return (uint8_t)LINV2_DATA_LEN_ID_CHECKSUM_GET(ptr->DATA_LEN_ID);
249 }
250 
257 static inline uint8_t lin_is_active(LINV2_Type *ptr)
258 {
260 }
261 
268 static inline uint8_t lin_is_complete(LINV2_Type *ptr)
269 {
271 }
272 
281 
289 hpm_stat_t lin_slave_configure_timing(LINV2_Type *ptr, uint32_t src_freq_in_hz);
290 
298 
308 
317 uint8_t lin_get_data_length(LINV2_Type *ptr);
318 
328 
338 
348 
358 
366 
367 #ifdef __cplusplus
368 }
369 #endif
370 
375 #endif /* HPM_LINV2_DRV_H */
376 
#define LINV2_TIMING_CONTROL_BUS_INACTIVE_TIME_MASK
Definition: hpm_linv2_regs.h:353
#define LINV2_TIMING_CONTROL_BUS_INACTIVE_TIME_SET(x)
Definition: hpm_linv2_regs.h:355
#define LINV2_CONTROL_STATUS_DATA_ACK_MASK
Definition: hpm_linv2_regs.h:254
#define LINV2_TIMING_CONTROL_WUP_REPEAT_TIME_SET(x)
Definition: hpm_linv2_regs.h:365
#define LINV2_DATA_LEN_ID_ID_GET(x)
Definition: hpm_linv2_regs.h:71
#define LINV2_CONTROL_STATUS_WAKEUP_REQ_MASK
Definition: hpm_linv2_regs.h:284
#define LINV2_TIMING_CONTROL_MASTER_MODE_MASK
Definition: hpm_linv2_regs.h:343
#define LINV2_DATA_LEN_ID_ENH_CHECK_MASK
Definition: hpm_linv2_regs.h:78
#define LINV2_CONTROL_STATUS_RESET_ERROR_MASK
Definition: hpm_linv2_regs.h:274
#define LINV2_CONTROL_STATUS_RESET_INT_MASK
Definition: hpm_linv2_regs.h:264
#define LINV2_DATA_LEN_ID_CHECKSUM_GET(x)
Definition: hpm_linv2_regs.h:53
#define LINV2_CONTROL_STATUS_COMPLETE_MASK
Definition: hpm_linv2_regs.h:215
#define LINV2_CONTROL_STATUS_STOP_MASK
Definition: hpm_linv2_regs.h:224
#define LINV2_CONTROL_STATUS_LIN_ACTIVE_MASK
Definition: hpm_linv2_regs.h:152
#define LINV2_CONTROL_STATUS_SLEEP_MASK
Definition: hpm_linv2_regs.h:234
#define LINV2_TIMING_CONTROL_WUP_REPEAT_TIME_MASK
Definition: hpm_linv2_regs.h:363
uint32_t hpm_stat_t
Definition: hpm_common.h:126
lin_wakeup_repeat_time_t
wakeup repeat time
Definition: hpm_lin_drv.h:51
lin_bus_inactivity_time_t
bus inactivity tome to go to sleep
Definition: hpm_lin_drv.h:41
void lin_master_transfer(LINV2_Type *ptr, lin_trans_config_t *config)
lin transfer on master mode
Definition: hpm_linv2_drv.c:99
lin_id_data_length_t
data length in ID bit4 and bit5
Definition: hpm_linv2_drv.h:31
static uint8_t lin_is_active(LINV2_Type *ptr)
lin active status
Definition: hpm_linv2_drv.h:257
static uint8_t lin_get_checksum(LINV2_Type *ptr)
lin get checksum value
Definition: hpm_linv2_drv.h:246
static uint8_t lin_get_id(LINV2_Type *ptr)
lin get ID
Definition: hpm_linv2_drv.h:235
static void lin_reset_error(LINV2_Type *ptr)
lin reset error
Definition: hpm_linv2_drv.h:106
hpm_stat_t lin_slave_receive(LINV2_Type *ptr, lin_trans_config_t *config)
lin receive data on slave mode
Definition: hpm_linv2_drv.c:313
static void lin_set_checksum_mode(LINV2_Type *ptr, bool enhance_checksum)
lin set checksum mode
Definition: hpm_linv2_drv.h:196
static uint8_t lin_get_data_byte(LINV2_Type *ptr, uint8_t index)
lin get data value in byte
Definition: hpm_linv2_drv.h:212
void lin_slave_dma_transfer(LINV2_Type *ptr, lin_trans_config_t *config)
lin slave dma transfer
Definition: hpm_linv2_drv.c:366
static void lin_set_mode(LINV2_Type *ptr, bool master)
lin set mode
Definition: hpm_linv2_drv.h:181
static void lin_slave_ack(LINV2_Type *ptr)
lin slave ack
Definition: hpm_linv2_drv.h:146
uint8_t lin_get_data_length(LINV2_Type *ptr)
get data length
Definition: hpm_linv2_drv.c:88
static uint32_t lin_get_control_and_status(LINV2_Type *ptr)
lin get control and status register value
Definition: hpm_linv2_drv.h:86
static void lin_reset_interrupt(LINV2_Type *ptr)
lin reset interrupt
Definition: hpm_linv2_drv.h:96
void lin_slave_transfer(LINV2_Type *ptr, lin_trans_config_t *config)
lin transfer on slave mode
Definition: hpm_linv2_drv.c:231
static void lin_slave_set_wakeup_repeat_time(LINV2_Type *ptr, lin_wakeup_repeat_time_t time)
lin slave set wakeup repeat time
Definition: hpm_linv2_drv.h:169
hpm_stat_t lin_master_sent(LINV2_Type *ptr, lin_trans_config_t *config)
lin send data on master mode
Definition: hpm_linv2_drv.c:128
hpm_stat_t lin_master_configure_timing(LINV2_Type *ptr, lin_timing_t *timing)
lin configure timing on master mode
Definition: hpm_linv2_drv.c:12
lin_wakeup_repeat_time_t
wakeup repeat time
Definition: hpm_linv2_drv.h:51
static void lin_write_data_byte(LINV2_Type *ptr, uint8_t index, uint8_t data)
lin write data value in byte
Definition: hpm_linv2_drv.h:224
hpm_stat_t lin_master_receive(LINV2_Type *ptr, lin_trans_config_t *config)
lin receive data on master mode
Definition: hpm_linv2_drv.c:179
static void lin_slave_stop(LINV2_Type *ptr)
lin slave stop
Definition: hpm_linv2_drv.h:136
static void lin_wakeup(LINV2_Type *ptr)
lin wakeup
Definition: hpm_linv2_drv.h:116
static void lin_slave_set_bus_inactivity_time(LINV2_Type *ptr, lin_bus_inactivity_time_t time)
lin slave set bus inactivity time
Definition: hpm_linv2_drv.h:157
lin_bus_inactivity_time_t
bus inactivity tome to go to sleep
Definition: hpm_linv2_drv.h:41
hpm_stat_t lin_slave_sent(LINV2_Type *ptr, lin_trans_config_t *config)
lin send data on slave mode
Definition: hpm_linv2_drv.c:261
static uint8_t lin_is_complete(LINV2_Type *ptr)
lin complete status
Definition: hpm_linv2_drv.h:268
hpm_stat_t lin_slave_configure_timing(LINV2_Type *ptr, uint32_t src_freq_in_hz)
lin config timing on slave mode
Definition: hpm_linv2_drv.c:42
static void lin_sleep(LINV2_Type *ptr)
lin sleep
Definition: hpm_linv2_drv.h:126
@ id_data_length_2bytes
Definition: hpm_linv2_drv.h:32
@ id_data_length_4bytes
Definition: hpm_linv2_drv.h:34
@ id_data_length_8bytes
Definition: hpm_linv2_drv.h:35
@ id_data_length_2bytes_2
Definition: hpm_linv2_drv.h:33
@ wakeup_repeat_time_240ms
Definition: hpm_linv2_drv.h:55
@ wakeup_repeat_time_200ms
Definition: hpm_linv2_drv.h:53
@ wakeup_repeat_time_180ms
Definition: hpm_linv2_drv.h:52
@ wakeup_repeat_time_220ms
Definition: hpm_linv2_drv.h:54
@ bus_inactivity_time_10s
Definition: hpm_linv2_drv.h:45
@ bus_inactivity_time_6s
Definition: hpm_linv2_drv.h:43
@ bus_inactivity_time_4s
Definition: hpm_linv2_drv.h:42
@ bus_inactivity_time_8s
Definition: hpm_linv2_drv.h:44
Definition: hpm_linv2_regs.h:12
__RW uint32_t DATA_LEN_ID
Definition: hpm_linv2_regs.h:17
__RW uint8_t DATA_BYTE[8]
Definition: hpm_linv2_regs.h:15
__RW uint32_t CONTROL_STATUS
Definition: hpm_linv2_regs.h:18
__RW uint32_t TIMING_CONTROL
Definition: hpm_linv2_regs.h:19
Definition: hpm_lin_drv.h:58
LIN config.
Definition: hpm_lin_drv.h:66