63 #ifdef LPUART_ERR_IRQS
77 #ifdef LPUART_ERR_IRQS
95 uint32_t timeoutMSec);
114 uint32_t twoBitTimeLength);
117 uint32_t twoBitTimeLength);
143 uint32_t linSourceClockFreq = 0U;
151 #if (LPUART_INSTANCE_COUNT > 1U)
156 #if (LPUART_INSTANCE_COUNT > 2U)
158 linLpuartClkName = LPUART2_CLK;
161 #if (LPUART_INSTANCE_COUNT > 3U)
163 linLpuartClkName = LPUART3_CLK;
181 g_linStatePtr[instance] = linCurrentState;
184 g_linUserconfigPtr[instance] = linUserConfig;
232 LPUART_SetBreakCharTransmitLength(base, LPUART_BREAK_CHAR_13_BIT_MINIMUM);
236 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_13_BIT_MINIMUM);
239 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
true);
242 LPUART_SetIntMode(base, LPUART_INT_FRAME_ERR_FLAG,
true);
245 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
true);
251 #ifdef LPUART_ERR_IRQS
272 if (linUserConfig->
baudRate > 10000U)
286 LPUART_SetTransmitterCmd(base,
true);
287 LPUART_SetReceiverCmd(base,
true);
313 lin_state_t * linCurrentState = g_linStatePtr[instance];
320 while (!LPUART_GetStatusFlag(base, LPUART_TX_COMPLETE))
326 LPUART_SetTransmitterCmd(base,
false);
327 LPUART_SetReceiverCmd(base,
false);
342 #ifdef LPUART_ERR_IRQS
350 g_linStatePtr[instance] = NULL;
371 lin_state_t * linCurrentState = g_linStatePtr[instance];
377 linCurrentState->
Callback =
function;
379 return currentCallback;
396 const uint8_t * txBuff,
398 uint32_t timeoutMSec)
408 lin_state_t * linCurrentState = g_linStatePtr[instance];
416 if ((8U < txSize) || (0U == txSize) || checkSleepMode)
433 linCurrentState->
txBuff = txBuff;
435 linCurrentState->
txSize = (uint8_t)(txSize + 1U);
443 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
449 LPUART_Putchar(base, *linCurrentState->
txBuff);
481 const uint8_t * txBuff,
494 lin_state_t * linCurrentState = g_linStatePtr[instance];
501 if ((8U < txSize) || (0U == txSize) || checkSleepMode)
518 linCurrentState->
txBuff = txBuff;
520 linCurrentState->
txSize = (uint8_t)(txSize + 1U);
528 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
531 LPUART_Putchar(base, *linCurrentState->
txBuff);
552 uint8_t * bytesRemaining)
560 const lin_state_t * linCurrentState = g_linStatePtr[instance];
563 *bytesRemaining = (uint8_t)(linCurrentState->
txSize - linCurrentState->
cntByte);
599 uint32_t timeoutMSec)
609 lin_state_t * linCurrentState = g_linStatePtr[instance];
617 if ((8U < rxSize) || (0U == rxSize) || checkSleepMode)
631 linCurrentState->
rxBuff = rxBuff;
633 linCurrentState->
rxSize = (uint8_t)(rxSize + 1U);
644 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
701 lin_state_t * linCurrentState = g_linStatePtr[instance];
708 if ((8U < rxSize) || (0U == rxSize) || checkSleepMode)
722 linCurrentState->
rxBuff = rxBuff;
724 linCurrentState->
rxSize = (uint8_t)(rxSize + 1U);
735 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
759 lin_state_t * linCurrentState = g_linStatePtr[instance];
784 uint8_t * bytesRemaining)
792 const lin_state_t * linCurrentState = g_linStatePtr[instance];
795 *bytesRemaining = (uint8_t)(linCurrentState->
rxSize - linCurrentState->
cntByte);
830 lin_state_t * linCurrentState = g_linStatePtr[instance];
836 LPUART_SetRxDataPolarity(base,
false);
839 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
false);
842 LPUART_SetIntMode(base, LPUART_INT_RX_ACTIVE_EDGE,
true);
845 LPUART_SetIntMode(base, LPUART_INT_FRAME_ERR_FLAG,
false);
848 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
false);
868 const lin_state_t * linCurrentState = g_linStatePtr[instance];
899 const lin_state_t * linCurrentState = g_linStatePtr[instance];
901 if (linCurrentState != NULL)
925 lin_state_t * linCurrentState = g_linStatePtr[instance];
943 if (linCurrentState->
Callback != NULL)
945 linCurrentState->
Callback(instance, linCurrentState);
974 if (linCurrentState->
Callback != NULL)
976 linCurrentState->
Callback(instance, linCurrentState);
1008 uint32_t timeoutValue)
1014 lin_state_t * linCurrentState = g_linStatePtr[instance];
1052 lin_state_t * linCurrentState = g_linStatePtr[instance];
1059 if ((linUserConfig->
nodeFunction == (
bool)
SLAVE) || (0x3FU < id) || checkSleepMode)
1083 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_13_BIT_MINIMUM);
1084 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
true);
1087 LPUART_QueueBreakField(base);
1112 const lin_state_t * linCurrentState = g_linStatePtr[instance];
1117 LPUART_SetIntMode(base, LPUART_INT_RX_ACTIVE_EDGE,
true);
1122 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
true);
1125 LPUART_SetIntMode(base, LPUART_INT_FRAME_ERR_FLAG,
true);
1128 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
true);
1133 #ifdef LPUART_ERR_IRQS
1158 const lin_state_t * linCurrentState = g_linStatePtr[instance];
1163 LPUART_SetIntMode(base, LPUART_INT_RX_ACTIVE_EDGE,
false);
1168 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
false);
1171 LPUART_SetIntMode(base, LPUART_INT_FRAME_ERR_FLAG,
false);
1174 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
false);
1179 #ifdef LPUART_ERR_IRQS
1199 lin_state_t * linCurrentState = g_linStatePtr[instance];
1204 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_13_BIT_MINIMUM);
1207 LPUART_SetRxDataPolarity(base,
false);
1210 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
true);
1213 LPUART_SetIntMode(base, LPUART_INT_RX_ACTIVE_EDGE,
false);
1216 LPUART_SetIntMode(base, LPUART_INT_FRAME_ERR_FLAG,
true);
1219 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
true);
1236 uint32_t timeoutMSec)
1239 lin_state_t * linCurrentState = g_linStatePtr[instance];
1242 if (linCurrentState->
isTxBusy ==
true)
1250 if (linCurrentState->
isRxBusy ==
true)
1276 uint8_t tmpByte = 0U;
1282 lin_state_t * linCurrentState = g_linStatePtr[instance];
1285 bool activeEdgeIntState = LPUART_GetIntMode(base, LPUART_INT_RX_ACTIVE_EDGE);
1288 if (LPUART_GetStatusFlag(base, LPUART_LIN_BREAK_DETECT))
1295 if (LPUART_GetStatusFlag(base, LPUART_RX_ACTIVE_EDGE_DETECT) && activeEdgeIntState)
1298 (void)LPUART_ClearStatusFlag(base, LPUART_RX_ACTIVE_EDGE_DETECT);
1306 if (LPUART_GetStatusFlag(base, LPUART_FRAME_ERR))
1309 (void)LPUART_ClearStatusFlag(base, LPUART_FRAME_ERR);
1312 LPUART_Getchar(base, &tmpByte);
1321 if (linCurrentState->
Callback != NULL)
1323 linCurrentState->
Callback(instance, linCurrentState);
1332 if (linCurrentState->
Callback != NULL)
1334 linCurrentState->
Callback(instance, linCurrentState);
1346 if (LPUART_GetStatusFlag(base, LPUART_RX_DATA_REG_FULL))
1349 LPUART_Getchar(base, &tmpByte);
1359 if (LPUART_GetStatusFlag(base, LPUART_RX_OVERRUN))
1362 (void)LPUART_ClearStatusFlag(base, LPUART_RX_OVERRUN);
1382 lin_state_t * linCurrentState = g_linStatePtr[instance];
1385 (void)LPUART_ClearStatusFlag(base, LPUART_LIN_BREAK_DETECT);
1396 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
1398 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
false);
1412 LPUART_Putchar(base, 0x55);
1422 if (linCurrentState->
Callback != NULL)
1424 linCurrentState->
Callback(instance, linCurrentState);
1443 uint32_t wakeupSignalLength = 0U;
1452 lin_state_t * linCurrentState = g_linStatePtr[instance];
1455 if (LPUART_GetRxDataPolarity(base) ==
false)
1461 LPUART_SetRxDataPolarity(base,
true);
1466 LPUART_SetRxDataPolarity(base,
false);
1472 if ((wakeupSignalLength >= 150000U) && (wakeupSignalLength <= 5000000U))
1477 if (linCurrentState->
Callback != NULL)
1479 linCurrentState->
Callback(instance, linCurrentState);
1500 const lin_state_t * linCurrentState = g_linStatePtr[instance];
1548 lin_state_t * linCurrentState = g_linStatePtr[instance];
1555 if (tmpByte == 0x55U)
1567 if (linCurrentState->
Callback != NULL)
1569 linCurrentState->
Callback(instance, linCurrentState);
1583 if (tmpByte == 0x55U)
1588 LPUART_Putchar(base, linCurrentState->
currentPid);
1605 if (linCurrentState->
Callback != NULL)
1607 linCurrentState->
Callback(instance, linCurrentState);
1627 if (linCurrentState->
Callback != NULL)
1629 linCurrentState->
Callback(instance, linCurrentState);
1646 if (linCurrentState->
Callback != NULL)
1648 linCurrentState->
Callback(instance, linCurrentState);
1658 if (linCurrentState->
currentId != 0xFFU)
1667 if (linCurrentState->
Callback != NULL)
1669 linCurrentState->
Callback(instance, linCurrentState);
1678 if (linCurrentState->
Callback != NULL)
1680 linCurrentState->
Callback(instance, linCurrentState);
1709 lin_state_t * linCurrentState = g_linStatePtr[instance];
1711 if (linCurrentState->
rxSize > (linCurrentState->
cntByte + 1U))
1713 *(linCurrentState->
rxBuff) = tmpByte;
1714 linCurrentState->
rxBuff++;
1718 if ((linCurrentState->
rxSize - linCurrentState->
cntByte) == 1U)
1720 linCurrentState->
checkSum = tmpByte;
1728 linCurrentState->
rxBuff -= linCurrentState->
rxSize - 1U;
1735 if (linCurrentState->
Callback != NULL)
1737 linCurrentState->
Callback(instance, linCurrentState);
1764 if (linCurrentState->
Callback != NULL)
1766 linCurrentState->
Callback(instance, linCurrentState);
1788 bool sendFlag =
true;
1790 bool tmpCheckSumAndSize;
1791 bool tmpBuffAndSize;
1797 lin_state_t * linCurrentState = g_linStatePtr[instance];
1800 if (LPUART_GetStatusFlag(base, LPUART_TX_DATA_REG_EMPTY) ==
false)
1804 if (linCurrentState->
Callback != NULL)
1806 linCurrentState->
Callback(instance, linCurrentState);
1823 tmpSize = (uint8_t)(linCurrentState->
txSize - linCurrentState->
cntByte);
1824 tmpCheckSumAndSize = (tmpSize == 1U) && (linCurrentState->
checkSum != tmpByte);
1825 tmpBuffAndSize = (*linCurrentState->
txBuff != tmpByte) && (tmpSize != 1U);
1826 if (tmpBuffAndSize || tmpCheckSumAndSize)
1831 if (linCurrentState->
Callback != NULL)
1833 linCurrentState->
Callback(instance, linCurrentState);
1850 linCurrentState->
txBuff++;
1860 if ((linCurrentState->
txSize - linCurrentState->
cntByte) == 1U)
1862 LPUART_Putchar(base, linCurrentState->
checkSum);
1867 LPUART_Putchar(base, *linCurrentState->
txBuff);
1875 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
false);
1877 if (linCurrentState->
Callback != NULL)
1879 linCurrentState->
Callback(instance, linCurrentState);
1911 uint32_t twoBitTimeLength)
1916 uint32_t MasterBaudRate = 0U;
1922 lin_state_t * linCurrentState = g_linStatePtr[instance];
1934 MasterBaudRate = 19200U;
1938 MasterBaudRate = 14400U;
1942 MasterBaudRate = 9600U;
1946 MasterBaudRate = 4800U;
1950 MasterBaudRate = 2400U;
1958 if ((MasterBaudRate != 0U) && (linUserConfig->
baudRate != MasterBaudRate))
1960 linUserConfig->
baudRate = MasterBaudRate;
1968 if (linUserConfig->
baudRate > 10000U)
1984 if (linCurrentState->
Callback != NULL)
1986 linCurrentState->
Callback(instance, linCurrentState);
2005 uint32_t twoBitTimeLength)
2011 lin_state_t * linCurrentState = g_linStatePtr[instance];
2068 lin_state_t * linCurrentState = g_linStatePtr[instance];
2070 uint32_t tmpTime = 0U;
2087 if ((tmpTime >= 150000U) && (tmpTime <= 5000000U))
2092 if (linCurrentState->
Callback != NULL)
2094 linCurrentState->
Callback(instance, linCurrentState);
2113 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
2116 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
false);
2125 if (linCurrentState->
Callback != NULL)
2127 linCurrentState->
Callback(instance, linCurrentState);
2168 LPUART_SetTransmitterCmd(base,
true);
2169 LPUART_SetReceiverCmd(base,
true);
lin_node_state_t
Define type for an enumerating LIN Node state. Implements : lin_node_state_t_Class.
LPUART_Type *const g_linLpuartBase[LPUART_INSTANCE_COUNT]
Table of base addresses for LPUART instances.
volatile bool timeoutCounterFlag
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.
volatile bool baudrateEvalEnable
status_t LIN_LPUART_DRV_SendWakeupSignal(uint32_t instance)
Sends a wakeup signal through the LIN_LPUART interface.
status_t OSIF_SemaDestroy(const semaphore_t *const pSem)
Destroys a previously created semaphore.
volatile lin_event_id_t currentEventId
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...
static void LIN_LPUART_DRV_CheckWakeupSignal(uint32_t instance)
volatile uint32_t timeoutCounter
static void LIN_LPUART_DRV_ProcessFrameHeader(uint32_t instance, uint8_t tmpByte)
lin_user_config_t * g_linUserconfigPtr[LPUART_INSTANCE_COUNT]
Table to save LIN user config structure pointers.
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_callback_t)(uint32_t instance, void *linState)
LIN Driver callback function type Implements : lin_callback_t_Class.
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 OSIF_SemaCreate(semaphore_t *const pSem, const uint8_t initValue)
Creates a semaphore with a given value.
static void LIN_LPUART_DRV_EvalTwoBitTimeLength(uint32_t instance, uint32_t twoBitTimeLength)
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...
static uint32_t s_timeMeasure[LPUART_INSTANCE_COUNT]
#define TWO_BIT_DURATION_MAX_4800
static uint8_t s_countMeasure[LPUART_INSTANCE_COUNT]
status_t LIN_LPUART_DRV_DisableIRQ(uint32_t instance)
Disables LIN_LPUART hardware interrupts.
volatile lin_node_state_t currentNodeState
void INT_SYS_DisableIRQ(IRQn_Type irqNumber)
Disables an interrupt for a given IRQ number.
#define TWO_BIT_DURATION_MAX_14400
status_t LIN_LPUART_DRV_AutoBaudCapture(uint32_t instance)
LIN_LPUART capture time interval to set baudrate automatically when enable autobaud feature...
static void LIN_LPUART_DRV_ProcessReceiveFrameData(uint32_t instance, uint8_t tmpByte)
void LIN_LPUART_DRV_SetTimeoutCounter(uint32_t instance, uint32_t timeoutValue)
Set Value for Timeout Counter that is used in LIN_LPUART_DRV_TimeoutService.
clock_names_t
Clock names.
#define TWO_BIT_DURATION_MIN_9600
const IRQn_Type g_linLpuartRxTxIrqId[LPUART_INSTANCE_COUNT]
Table to save LPUART IRQ enumeration numbers defined in the device header file.
uint32_t linSourceClockFreq
#define TWO_BIT_DURATION_MIN_14400
volatile uint8_t fallingEdgeInterruptCount
status_t CLOCK_SYS_GetFreq(clock_names_t clockName, uint32_t *frequency)
Gets the clock frequency for a specific clock name.
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
#define TWO_BIT_DURATION_MAX_19200
lin_timer_get_time_interval_t timerGetTimeIntervalCallback
uint8_t LIN_DRV_ProcessParity(uint8_t PID, uint8_t typeAction)
Makes or checks parity bits. If action is checking parity, the function returns ID value if parity bi...
status_t LPUART_DRV_SetBaudRate(uint32_t instance, uint32_t desiredBaudRate)
Configures the LPUART baud rate.
#define TWO_BIT_DURATION_MIN_2400
static status_t LIN_LPUART_DRV_WaitComplete(uint32_t instance, uint32_t timeoutMSec)
static void LIN_LPUART_DRV_ProcessFrame(uint32_t instance, uint8_t tmpByte)
static void LIN_LPUART_DRV_ProcessBreakDetect(uint32_t instance)
volatile bool isRxBlocking
void LIN_LPUART_DRV_TimeoutService(uint32_t instance)
Callback function for Timer Interrupt Handler Users shall initialize a timer (for example FTM) in Out...
static uint8_t s_wakeupSignal[LPUART_INSTANCE_COUNT]
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...
Runtime state of the LIN driver.
status_t OSIF_SemaWait(semaphore_t *const pSem, const uint32_t timeout)
Decrement a semaphore with timeout.
#define TWO_BIT_DURATION_MIN_4800
LIN hardware configuration structure Implements : lin_user_config_t_Class.
volatile bool isTxBlocking
static void LIN_LPUART_DRV_ProcessSendFrameData(uint32_t instance, uint8_t tmpByte)
#define AUTOBAUD_BREAK_TIME_MIN
status_t OSIF_SemaPost(semaphore_t *const pSem)
Increment a semaphore.
static uint32_t s_previousTwoBitTimeLength[LPUART_INSTANCE_COUNT]
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...
#define LPUART_INSTANCE_COUNT
#define TWO_BIT_DURATION_MAX_2400
void INT_SYS_EnableIRQ(IRQn_Type irqNumber)
Enables an interrupt for a given IRQ number.
lin_node_state_t LIN_LPUART_DRV_GetCurrentNodeState(uint32_t instance)
Get the current LIN node state.
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.
status_t LIN_LPUART_DRV_AbortTransferData(uint32_t instance)
Aborts an on-going non-blocking transmission/reception. While performing a non-blocking transferring ...
#define TWO_BIT_DURATION_MIN_19200
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...
isr_t g_linLpuartIsrs[LPUART_INSTANCE_COUNT]
#define TWO_BIT_DURATION_MAX_9600
static void LIN_LPUART_DRV_AutobaudTimerValEval(uint32_t instance, uint32_t twoBitTimeLength)
void LIN_LPUART_DRV_IRQHandler(uint32_t instance)
LIN_LPUART interrupt handler for RX_TX and Error interrupts.
uint8_t LIN_DRV_MakeChecksumByte(const uint8_t *buffer, uint8_t sizeBuffer, uint8_t PID)
Makes the checksum byte for a frame.
lin_state_t * g_linStatePtr[LPUART_INSTANCE_COUNT]
Table to save LPUART state structure pointers.
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.
void(* isr_t)(void)
Interrupt handler type.
#define BIT_RATE_TOLERANCE_UNSYNC
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...
#define LPUART_RX_TX_IRQS
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.
IRQn_Type
Defines the Interrupt Numbers definitions.
void INT_SYS_InstallHandler(IRQn_Type irqNumber, const isr_t newHandler, isr_t *const oldHandler)
Installs an interrupt handler routine for a given IRQ number.