67 #ifdef LPUART_ERR_IRQS
81 #ifdef LPUART_ERR_IRQS
99 uint32_t timeoutMSec);
118 uint32_t twoBitTimeLength);
121 uint32_t twoBitTimeLength);
147 uint32_t linSourceClockFreq = 0U;
155 #if (LPUART_INSTANCE_COUNT > 1U)
160 #if (LPUART_INSTANCE_COUNT > 2U)
162 linLpuartClkName = LPUART2_CLK;
165 #if (LPUART_INSTANCE_COUNT > 3U)
167 linLpuartClkName = LPUART3_CLK;
185 g_linStatePtr[instance] = linCurrentState;
188 g_linUserconfigPtr[instance] = linUserConfig;
236 LPUART_SetBreakCharTransmitLength(base, LPUART_BREAK_CHAR_13_BIT_MINIMUM);
240 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_13_BIT_MINIMUM);
243 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
true);
246 LPUART_SetIntMode(base, LPUART_INT_FRAME_ERR_FLAG,
true);
249 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
true);
255 #ifdef LPUART_ERR_IRQS
276 if (linUserConfig->
baudRate > 10000U)
290 LPUART_SetTransmitterCmd(base,
true);
291 LPUART_SetReceiverCmd(base,
true);
317 lin_state_t * linCurrentState = g_linStatePtr[instance];
324 while (!LPUART_GetStatusFlag(base, LPUART_TX_COMPLETE))
330 LPUART_SetTransmitterCmd(base,
false);
331 LPUART_SetReceiverCmd(base,
false);
346 #ifdef LPUART_ERR_IRQS
354 g_linStatePtr[instance] = NULL;
375 lin_state_t * linCurrentState = g_linStatePtr[instance];
381 linCurrentState->
Callback =
function;
383 return currentCallback;
400 const uint8_t * txBuff,
402 uint32_t timeoutMSec)
412 lin_state_t * linCurrentState = g_linStatePtr[instance];
420 if ((8U < txSize) || (0U == txSize) || checkSleepMode)
437 linCurrentState->
txBuff = txBuff;
439 linCurrentState->
txSize = (uint8_t)(txSize + 1U);
447 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
453 LPUART_Putchar(base, *linCurrentState->
txBuff);
485 const uint8_t * txBuff,
498 lin_state_t * linCurrentState = g_linStatePtr[instance];
505 if ((8U < txSize) || (0U == txSize) || checkSleepMode)
522 linCurrentState->
txBuff = txBuff;
524 linCurrentState->
txSize = (uint8_t)(txSize + 1U);
532 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
535 LPUART_Putchar(base, *linCurrentState->
txBuff);
556 uint8_t * bytesRemaining)
564 const lin_state_t * linCurrentState = g_linStatePtr[instance];
567 *bytesRemaining = (uint8_t)(linCurrentState->
txSize - linCurrentState->
cntByte);
603 uint32_t timeoutMSec)
610 lin_state_t * linCurrentState = g_linStatePtr[instance];
618 if ((8U < rxSize) || (0U == rxSize) || checkSleepMode)
632 linCurrentState->
rxBuff = rxBuff;
634 linCurrentState->
rxSize = (uint8_t)(rxSize + 1U);
696 lin_state_t * linCurrentState = g_linStatePtr[instance];
703 if ((8U < rxSize) || (0U == rxSize) || checkSleepMode)
717 linCurrentState->
rxBuff = rxBuff;
719 linCurrentState->
rxSize = (uint8_t)(rxSize + 1U);
730 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
754 lin_state_t * linCurrentState = g_linStatePtr[instance];
778 uint8_t * bytesRemaining)
786 const lin_state_t * linCurrentState = g_linStatePtr[instance];
789 *bytesRemaining = (uint8_t)(linCurrentState->
rxSize - linCurrentState->
cntByte);
824 lin_state_t * linCurrentState = g_linStatePtr[instance];
830 LPUART_SetRxDataPolarity(base,
false);
833 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
false);
836 LPUART_SetIntMode(base, LPUART_INT_RX_ACTIVE_EDGE,
true);
839 LPUART_SetIntMode(base, LPUART_INT_FRAME_ERR_FLAG,
false);
842 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
false);
862 const lin_state_t * linCurrentState = g_linStatePtr[instance];
893 const lin_state_t * linCurrentState = g_linStatePtr[instance];
895 if (linCurrentState != NULL)
919 lin_state_t * linCurrentState = g_linStatePtr[instance];
937 if (linCurrentState->
Callback != NULL)
939 linCurrentState->
Callback(instance, linCurrentState);
967 if (linCurrentState->
Callback != NULL)
969 linCurrentState->
Callback(instance, linCurrentState);
1001 uint32_t timeoutValue)
1007 lin_state_t * linCurrentState = g_linStatePtr[instance];
1045 lin_state_t * linCurrentState = g_linStatePtr[instance];
1052 if ((linUserConfig->
nodeFunction == (
bool)
SLAVE) || (0x3FU < id) || checkSleepMode)
1076 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_13_BIT_MINIMUM);
1077 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
true);
1080 LPUART_QueueBreakField(base);
1105 const lin_state_t * linCurrentState = g_linStatePtr[instance];
1110 LPUART_SetIntMode(base, LPUART_INT_RX_ACTIVE_EDGE,
true);
1115 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
true);
1118 LPUART_SetIntMode(base, LPUART_INT_FRAME_ERR_FLAG,
true);
1121 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
true);
1126 #ifdef LPUART_ERR_IRQS
1151 const lin_state_t * linCurrentState = g_linStatePtr[instance];
1156 LPUART_SetIntMode(base, LPUART_INT_RX_ACTIVE_EDGE,
false);
1161 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
false);
1164 LPUART_SetIntMode(base, LPUART_INT_FRAME_ERR_FLAG,
false);
1167 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
false);
1172 #ifdef LPUART_ERR_IRQS
1192 lin_state_t * linCurrentState = g_linStatePtr[instance];
1197 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_13_BIT_MINIMUM);
1200 LPUART_SetRxDataPolarity(base,
false);
1203 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
true);
1206 LPUART_SetIntMode(base, LPUART_INT_RX_ACTIVE_EDGE,
false);
1209 LPUART_SetIntMode(base, LPUART_INT_FRAME_ERR_FLAG,
true);
1212 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
true);
1232 uint32_t timeoutMSec)
1235 lin_state_t * linCurrentState = g_linStatePtr[instance];
1272 uint8_t tmpByte = 0U;
1278 lin_state_t * linCurrentState = g_linStatePtr[instance];
1281 bool activeEdgeIntState = LPUART_GetIntMode(base, LPUART_INT_RX_ACTIVE_EDGE);
1284 if (LPUART_GetStatusFlag(base, LPUART_LIN_BREAK_DETECT))
1291 if (LPUART_GetStatusFlag(base, LPUART_RX_ACTIVE_EDGE_DETECT) && activeEdgeIntState)
1294 (void)LPUART_ClearStatusFlag(base, LPUART_RX_ACTIVE_EDGE_DETECT);
1302 if (LPUART_GetStatusFlag(base, LPUART_FRAME_ERR))
1305 (void)LPUART_ClearStatusFlag(base, LPUART_FRAME_ERR);
1308 LPUART_Getchar(base, &tmpByte);
1317 if (linCurrentState->
Callback != NULL)
1319 linCurrentState->
Callback(instance, linCurrentState);
1328 if (linCurrentState->
Callback != NULL)
1330 linCurrentState->
Callback(instance, linCurrentState);
1340 if (LPUART_GetStatusFlag(base, LPUART_RX_DATA_REG_FULL))
1343 LPUART_Getchar(base, &tmpByte);
1353 if (LPUART_GetStatusFlag(base, LPUART_RX_OVERRUN))
1356 (void)LPUART_ClearStatusFlag(base, LPUART_RX_OVERRUN);
1362 if (linCurrentState->
Callback != NULL)
1364 linCurrentState->
Callback(instance, linCurrentState);
1385 lin_state_t * linCurrentState = g_linStatePtr[instance];
1388 (void)LPUART_ClearStatusFlag(base, LPUART_LIN_BREAK_DETECT);
1399 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
1401 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
false);
1416 LPUART_Putchar(base, 0x55);
1429 if (linCurrentState->
Callback != NULL)
1431 linCurrentState->
Callback(instance, linCurrentState);
1450 uint32_t wakeupSignalLength = 0U;
1459 lin_state_t * linCurrentState = g_linStatePtr[instance];
1462 if (LPUART_GetRxDataPolarity(base) ==
false)
1468 LPUART_SetRxDataPolarity(base,
true);
1473 LPUART_SetRxDataPolarity(base,
false);
1479 if ((wakeupSignalLength >= 150000U) && (wakeupSignalLength <= 5000000U))
1484 if (linCurrentState->
Callback != NULL)
1486 linCurrentState->
Callback(instance, linCurrentState);
1507 const lin_state_t * linCurrentState = g_linStatePtr[instance];
1555 lin_state_t * linCurrentState = g_linStatePtr[instance];
1562 if (tmpByte == 0x55U)
1574 if (linCurrentState->
Callback != NULL)
1576 linCurrentState->
Callback(instance, linCurrentState);
1587 if (tmpByte == 0x55U)
1592 LPUART_Putchar(base, linCurrentState->
currentPid);
1609 if (linCurrentState->
Callback != NULL)
1611 linCurrentState->
Callback(instance, linCurrentState);
1636 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
1644 if (linCurrentState->
Callback != NULL)
1646 linCurrentState->
Callback(instance, linCurrentState);
1664 if (linCurrentState->
Callback != NULL)
1666 linCurrentState->
Callback(instance, linCurrentState);
1676 if (linCurrentState->
currentId != 0xFFU)
1690 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
1698 if (linCurrentState->
Callback != NULL)
1700 linCurrentState->
Callback(instance, linCurrentState);
1710 if (linCurrentState->
Callback != NULL)
1712 linCurrentState->
Callback(instance, linCurrentState);
1738 lin_state_t * linCurrentState = g_linStatePtr[instance];
1740 if (linCurrentState->
rxSize > (linCurrentState->
cntByte + 1U))
1742 *(linCurrentState->
rxBuff) = tmpByte;
1743 linCurrentState->
rxBuff++;
1747 if ((linCurrentState->
rxSize - linCurrentState->
cntByte) == 1U)
1749 linCurrentState->
checkSum = tmpByte;
1757 linCurrentState->
rxBuff -= linCurrentState->
rxSize - 1U;
1764 if (linCurrentState->
Callback != NULL)
1766 linCurrentState->
Callback(instance, linCurrentState);
1795 if (linCurrentState->
Callback != NULL)
1797 linCurrentState->
Callback(instance, linCurrentState);
1819 bool sendFlag =
true;
1821 bool tmpCheckSumAndSize;
1822 bool tmpBuffAndSize;
1828 lin_state_t * linCurrentState = g_linStatePtr[instance];
1831 if (LPUART_GetStatusFlag(base, LPUART_TX_DATA_REG_EMPTY) ==
false)
1835 if (linCurrentState->
Callback != NULL)
1837 linCurrentState->
Callback(instance, linCurrentState);
1854 tmpSize = (uint8_t)(linCurrentState->
txSize - linCurrentState->
cntByte);
1855 tmpCheckSumAndSize = (tmpSize == 1U) && (linCurrentState->
checkSum != tmpByte);
1856 tmpBuffAndSize = (*linCurrentState->
txBuff != tmpByte) && (tmpSize != 1U);
1857 if (tmpBuffAndSize || tmpCheckSumAndSize)
1862 if (linCurrentState->
Callback != NULL)
1864 linCurrentState->
Callback(instance, linCurrentState);
1881 linCurrentState->
txBuff++;
1891 if ((linCurrentState->
txSize - linCurrentState->
cntByte) == 1U)
1893 LPUART_Putchar(base, linCurrentState->
checkSum);
1898 LPUART_Putchar(base, *linCurrentState->
txBuff);
1906 LPUART_SetIntMode(base, LPUART_INT_RX_DATA_REG_FULL,
false);
1908 if (linCurrentState->
Callback != NULL)
1910 linCurrentState->
Callback(instance, linCurrentState);
1942 uint32_t twoBitTimeLength)
1947 uint32_t MasterBaudRate = 0U;
1953 lin_state_t * linCurrentState = g_linStatePtr[instance];
1965 MasterBaudRate = 19200U;
1969 MasterBaudRate = 14400U;
1973 MasterBaudRate = 9600U;
1977 MasterBaudRate = 4800U;
1981 MasterBaudRate = 2400U;
1989 if ((MasterBaudRate != 0U) && (linUserConfig->
baudRate != MasterBaudRate))
1991 linUserConfig->
baudRate = MasterBaudRate;
1999 if (linUserConfig->
baudRate > 10000U)
2015 if (linCurrentState->
Callback != NULL)
2017 linCurrentState->
Callback(instance, linCurrentState);
2036 uint32_t twoBitTimeLength)
2042 lin_state_t * linCurrentState = g_linStatePtr[instance];
2099 lin_state_t * linCurrentState = g_linStatePtr[instance];
2101 uint32_t tmpTime = 0U;
2118 if ((tmpTime >= 150000U) && (tmpTime <= 5000000U))
2123 if (linCurrentState->
Callback != NULL)
2125 linCurrentState->
Callback(instance, linCurrentState);
2144 LPUART_SetBreakCharDetectLength(base, LPUART_BREAK_CHAR_10_BIT_MINIMUM);
2147 LPUART_SetIntMode(base, LPUART_INT_LIN_BREAK_DETECT,
false);
2156 if (linCurrentState->
Callback != NULL)
2158 linCurrentState->
Callback(instance, linCurrentState);
2199 LPUART_SetTransmitterCmd(base,
true);
2200 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.
#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 ...
IRQn_Type
Defines the Interrupt Numbers definitions.
#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.
clock_names_t
Clock names.
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.
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.