S32 SDK
lin_lpuart_driver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016 - 2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
23 #ifndef LIN_LPUART_DRIVER_H
24 #define LIN_LPUART_DRIVER_H
25 
26 /*******************************************************************************
27  * Includes
28  ******************************************************************************/
29 #include "lpuart_hal.h"
30 #include "clock_manager.h"
31 #include "lin_driver.h"
32 
33 /*******************************************************************************
34  * Definitions
35  ******************************************************************************/
38 
41 
42 #ifdef LPUART_ERR_IRQS
43 
44 extern const IRQn_Type g_linLpuartErrIrqId[LPUART_INSTANCE_COUNT];
45 #endif
46 
49 
52 
53 /* Accept Master baudrate deviation from the slave baudrate to be 2% */
54 #define AUTOBAUD_BAUDRATE_TOLERANCE (uint32_t)2U
55 #define BIT_RATE_TOLERANCE_UNSYNC (uint32_t)14U
56 /* calculate range of one bit time with baudrate 19200 by formula {1000000/19200*(100 + AUTOBAUD_BAUDRATE_TOLERANCE))/100} */
57 #define BIT_DURATION_MAX_19200 (uint32_t)(100000U * (100U + AUTOBAUD_BAUDRATE_TOLERANCE) / 192U)
58 #define BIT_DURATION_MIN_19200 (uint32_t)(100000U * (100U - AUTOBAUD_BAUDRATE_TOLERANCE) / 192U)
59 /* calculate range of one bit time with baudrate 14400 by formula {1000000/14400*(100 + AUTOBAUD_BAUDRATE_TOLERANCE))/100} */
60 #define BIT_DURATION_MAX_14400 (uint32_t)(100000U * (100U + AUTOBAUD_BAUDRATE_TOLERANCE) / 144U)
61 #define BIT_DURATION_MIN_14400 (uint32_t)(100000U * (100U - AUTOBAUD_BAUDRATE_TOLERANCE) / 144U)
62 /* calculate range of one bit time with baudrate 9600 by formula {1000000/9600*(100 + AUTOBAUD_BAUDRATE_TOLERANCE))/100} */
63 #define BIT_DURATION_MAX_9600 (uint32_t)(100000U * (100U + AUTOBAUD_BAUDRATE_TOLERANCE) / 96U)
64 #define BIT_DURATION_MIN_9600 (uint32_t)(100000U * (100U - AUTOBAUD_BAUDRATE_TOLERANCE) / 96U)
65 /* calculate range of one bit time with baudrate 4800 by formula {1000000/4800*(100 + AUTOBAUD_BAUDRATE_TOLERANCE))/100} */
66 #define BIT_DURATION_MAX_4800 (uint32_t)(100000U * (100U + AUTOBAUD_BAUDRATE_TOLERANCE) / 48U)
67 #define BIT_DURATION_MIN_4800 (uint32_t)(100000U * (100U - AUTOBAUD_BAUDRATE_TOLERANCE) / 48U)
68 /* calculate range of one bit time with baudrate 2400 by formula {1000000/2400*(100 + AUTOBAUD_BAUDRATE_TOLERANCE))/100} */
69 #define BIT_DURATION_MAX_2400 (uint32_t)(100000U * (100U + AUTOBAUD_BAUDRATE_TOLERANCE) / 24U)
70 #define BIT_DURATION_MIN_2400 (uint32_t)(100000U * (100U - AUTOBAUD_BAUDRATE_TOLERANCE) / 24U)
71 
72 /* calculate range of two bit time with baudrate 19200 */
73 #define TWO_BIT_DURATION_MAX_19200 (2U * BIT_DURATION_MAX_19200)
74 #define TWO_BIT_DURATION_MIN_19200 (2U * BIT_DURATION_MIN_19200)
75 /* calculate range of two bit time with baudrate 14400 */
76 #define TWO_BIT_DURATION_MAX_14400 (2U * BIT_DURATION_MAX_14400)
77 #define TWO_BIT_DURATION_MIN_14400 (2U * BIT_DURATION_MIN_14400)
78 /* calculate range of two bit time with baudrate 9600 */
79 #define TWO_BIT_DURATION_MAX_9600 (2U * BIT_DURATION_MAX_9600)
80 #define TWO_BIT_DURATION_MIN_9600 (2U * BIT_DURATION_MIN_9600)
81 /* calculate range of two bit time with baudrate 4800 */
82 #define TWO_BIT_DURATION_MAX_4800 (2U * BIT_DURATION_MAX_4800)
83 #define TWO_BIT_DURATION_MIN_4800 (2U * BIT_DURATION_MIN_4800)
84 /* calculate range of two bit time with baudrate 2400 */
85 #define TWO_BIT_DURATION_MAX_2400 (2U * BIT_DURATION_MAX_2400)
86 #define TWO_BIT_DURATION_MIN_2400 (2U * BIT_DURATION_MIN_2400)
87 
88 /* calculate range of 13 bit time minimum with baudrate 19200 for autobaud feature */
89 #define AUTOBAUD_BREAK_TIME_MIN (13U * BIT_DURATION_MIN_19200)
90 
91 /*******************************************************************************
92  * API
93  ******************************************************************************/
94 #if defined(__cplusplus)
95 extern "C" {
96 #endif
97 
115 status_t LIN_LPUART_DRV_Init(uint32_t instance,
116  lin_user_config_t * linUserConfig,
117  lin_state_t * linCurrentState);
118 
125 status_t LIN_LPUART_DRV_Deinit(uint32_t instance);
126 
138  lin_callback_t function);
139 
158  const uint8_t * txBuff,
159  uint8_t txSize,
160  uint32_t timeoutMSec);
161 
177 status_t LIN_LPUART_DRV_SendFrameData(uint32_t instance,
178  const uint8_t * txBuff,
179  uint8_t txSize);
180 
194  uint8_t * bytesRemaining);
195 
214  uint8_t * rxBuff,
215  uint8_t rxSize,
216  uint32_t timeoutMSec);
217 
235 status_t LIN_LPUART_DRV_RecvFrmData(uint32_t instance,
236  uint8_t * rxBuff,
237  uint8_t rxSize);
238 
247 status_t LIN_LPUART_DRV_AbortTransferData(uint32_t instance);
248 
261 status_t LIN_LPUART_DRV_GetReceiveStatus(uint32_t instance,
262  uint8_t * bytesRemaining);
263 
271 status_t LIN_LPUART_DRV_GoToSleepMode(uint32_t instance);
272 
280 status_t LIN_LPUART_DRV_GotoIdleState(uint32_t instance);
281 
288 status_t LIN_LPUART_DRV_SendWakeupSignal(uint32_t instance);
289 
297 
306 void LIN_LPUART_DRV_TimeoutService(uint32_t instance);
307 
315 void LIN_LPUART_DRV_SetTimeoutCounter(uint32_t instance,
316  uint32_t timeoutValue);
317 
329 status_t LIN_LPUART_DRV_MasterSendHeader(uint32_t instance,
330  uint8_t id);
331 
338 status_t LIN_LPUART_DRV_EnableIRQ(uint32_t instance);
339 
346 status_t LIN_LPUART_DRV_DisableIRQ(uint32_t instance);
347 
354 void LIN_LPUART_DRV_IRQHandler(uint32_t instance);
355 
371 status_t LIN_LPUART_DRV_AutoBaudCapture(uint32_t instance);
372 
373 #if defined(__cplusplus)
374 }
375 #endif
376 
377 #endif /* LIN_LPUART_DRIVER_H */
378 /******************************************************************************/
379 /* EOF */
380 /******************************************************************************/
lin_node_state_t
Define type for an enumerating LIN Node state. Implements : lin_node_state_t_Class.
Definition: lin_driver.h:97
status_t LIN_LPUART_DRV_GotoIdleState(uint32_t instance)
Puts current LIN node to Idle state This function changes current node state to LIN_NODE_STATE_IDLE.
void LIN_LPUART_DRV_TimeoutService(uint32_t instance)
Callback function for Timer Interrupt Handler Users shall initialize a timer (for example FTM) in Out...
lin_user_config_t * g_linUserconfigPtr[LPUART_INSTANCE_COUNT]
Table to save LIN user config structure pointers.
lin_callback_t LIN_LPUART_DRV_InstallCallback(uint32_t instance, lin_callback_t function)
Installs callback function that is used for LIN_LPUART_DRV_IRQHandler.
void(* lin_callback_t)(uint32_t instance, void *linState)
LIN Driver callback function type Implements : lin_callback_t_Class.
Definition: lin_driver.h:115
IRQn_Type
Defines the Interrupt Numbers definitions.
Definition: S32K144.h:269
void LIN_LPUART_DRV_IRQHandler(uint32_t instance)
LIN_LPUART interrupt handler for RX_TX and Error interrupts.
status_t LIN_LPUART_DRV_SendFrameDataBlocking(uint32_t instance, const uint8_t *txBuff, uint8_t txSize, uint32_t timeoutMSec)
Sends Frame data out through the LIN_LPUART module using blocking method. This function will calculat...
status_t LIN_LPUART_DRV_GoToSleepMode(uint32_t instance)
This function puts current node to sleep mode This function changes current node state to LIN_NODE_ST...
status_t LIN_LPUART_DRV_SendFrameData(uint32_t instance, const uint8_t *txBuff, uint8_t txSize)
Sends frame data out through the LIN_LPUART module using non-blocking method. This enables an a-sync ...
void LIN_LPUART_DRV_SetTimeoutCounter(uint32_t instance, uint32_t timeoutValue)
Set Value for Timeout Counter that is used in LIN_LPUART_DRV_TimeoutService.
status_t LIN_LPUART_DRV_DisableIRQ(uint32_t instance)
Disables LIN_LPUART hardware interrupts.
status_t LIN_LPUART_DRV_AbortTransferData(uint32_t instance)
Aborts an on-going non-blocking transmission/reception. While performing a non-blocking transferring ...
status_t LIN_LPUART_DRV_AutoBaudCapture(uint32_t instance)
LIN_LPUART capture time interval to set baudrate automatically when enable autobaud feature...
lin_state_t * g_linStatePtr[LPUART_INSTANCE_COUNT]
Table to save LPUART state structure pointers.
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:31
status_t LIN_LPUART_DRV_GetReceiveStatus(uint32_t instance, uint8_t *bytesRemaining)
Get status of an on-going non-blocking reception While receiving frame data using non-blocking method...
status_t LIN_LPUART_DRV_MasterSendHeader(uint32_t instance, uint8_t id)
Sends frame header out through the LIN_LPUART module using a non-blocking method. This function sends...
status_t LIN_LPUART_DRV_Init(uint32_t instance, lin_user_config_t *linUserConfig, lin_state_t *linCurrentState)
Initializes an LIN_LPUART instance for LIN Network.
Runtime state of the LIN driver.
Definition: lin_driver.h:124
lin_node_state_t LIN_LPUART_DRV_GetCurrentNodeState(uint32_t instance)
Get the current LIN node state.
LIN hardware configuration structure Implements : lin_user_config_t_Class.
Definition: lin_driver.h:66
status_t LIN_LPUART_DRV_GetTransmitStatus(uint32_t instance, uint8_t *bytesRemaining)
Get status of an on-going non-blocking transmission While sending frame data using non-blocking metho...
#define LPUART_INSTANCE_COUNT
Definition: S32K144.h:6683
LPUART_Type *const g_linLpuartBase[LPUART_INSTANCE_COUNT]
Table of base addresses for LPUART instances.
const IRQn_Type g_linLpuartRxTxIrqId[LPUART_INSTANCE_COUNT]
Table to save LPUART IRQ enumeration numbers defined in the device header file.
status_t LIN_LPUART_DRV_RecvFrmDataBlocking(uint32_t instance, uint8_t *rxBuff, uint8_t rxSize, uint32_t timeoutMSec)
Receives frame data through the LIN_LPUART module using blocking method. The function does not return...
status_t LIN_LPUART_DRV_SendWakeupSignal(uint32_t instance)
Sends a wakeup signal through the LIN_LPUART interface.
status_t LIN_LPUART_DRV_RecvFrmData(uint32_t instance, uint8_t *rxBuff, uint8_t rxSize)
Receives frame data through the LIN_LPUART module using non-blocking method. This function returns im...
status_t LIN_LPUART_DRV_EnableIRQ(uint32_t instance)
Enables LIN_LPUART hardware interrupts.
status_t LIN_LPUART_DRV_Deinit(uint32_t instance)
Shuts down the LIN_LPUART by disabling interrupts and transmitter/receiver.