CAT2 Peripheral Driver Library

Functions

cy_en_lin_status_t Cy_LIN_DeInit (LIN_CH_Type *base)
 Deinitialization of a LIN module. More...
 
cy_en_lin_status_t Cy_LIN_Init (LIN_CH_Type *base, const cy_stc_lin_config_t *pstcConfig)
 Initializes the LIN module. More...
 
cy_en_lin_status_t Cy_LIN_ReadData (const LIN_CH_Type *base, uint8_t *data)
 Reads response data. More...
 
cy_en_lin_status_t Cy_LIN_WriteData (LIN_CH_Type *base, const uint8_t *data, uint8_t dataLength)
 Writes response data. More...
 
cy_en_lin_status_t Cy_LIN_Enable (LIN_CH_Type *base)
 Enables LIN channel. More...
 
cy_en_lin_status_t Cy_LIN_Disable (LIN_CH_Type *base)
 Disables LIN channel. More...
 
cy_en_lin_status_t Cy_LIN_SetBreakWakeupFieldLength (LIN_CH_Type *base, uint8_t length)
 Sets LIN break/wakeup field length. More...
 
cy_en_lin_status_t Cy_LIN_SetDataLength (LIN_CH_Type *base, uint8_t length)
 Sets LIN response field data length. More...
 
cy_en_lin_status_t Cy_LIN_SetChecksumType (LIN_CH_Type *base, cy_en_lin_checksum_type_t type)
 Sets LIN checksum type setting. More...
 
cy_en_lin_status_t Cy_LIN_SetCmd (LIN_CH_Type *base, uint32_t command)
 Sets LIN operation command. More...
 
cy_en_lin_status_t Cy_LIN_SetHeader (LIN_CH_Type *base, uint8_t id)
 Sets LIN header for master tx header operation. More...
 
cy_en_lin_status_t Cy_LIN_GetHeader (const LIN_CH_Type *base, uint8_t *id, uint8_t *parity)
 Returns received LIN header. More...
 
cy_en_lin_status_t Cy_LIN_SetInterruptMask (LIN_CH_Type *base, uint32_t mask)
 Sets interrupt source to be accepted. More...
 
cy_en_lin_status_t Cy_LIN_GetInterruptMask (const LIN_CH_Type *base, uint32_t *mask)
 Returns interrupt mask setting. More...
 
cy_en_lin_status_t Cy_LIN_GetInterruptMaskedStatus (const LIN_CH_Type *base, uint32_t *status)
 Returns interrupt masked status. More...
 
cy_en_lin_status_t Cy_LIN_GetInterruptStatus (const LIN_CH_Type *base, uint32_t *status)
 Returns interrupt raw status. More...
 
cy_en_lin_status_t Cy_LIN_ClearInterrupt (LIN_CH_Type *base, uint32_t mask)
 Clears interrupt status. More...
 
cy_en_lin_status_t Cy_LIN_GetStatus (const LIN_CH_Type *base, uint32_t *status)
 
cy_en_lin_status_t Cy_LIN_EnOut_Enable (LIN_CH_Type *base)
 Enables LIN channel 'en' out. More...
 
cy_en_lin_status_t Cy_LIN_EnOut_Disable (LIN_CH_Type *base)
 Disables LIN channel 'en' out. More...
 
cy_en_lin_status_t Cy_LIN_TestMode_Enable (LIN_Type *base, const cy_stc_lin_test_config_t *linTestConfig)
 Enables LIN Testing mode. More...
 
cy_en_lin_status_t Cy_LIN_TestMode_Disable (LIN_Type *base)
 Disables LIN Testing mode. More...
 
cy_en_lin_status_t Cy_LIN_ErrCtl_Enable (LIN_Type *base, cy_stc_lin_test_error_config_t *testErrorConfig)
 Enables LIN ERROR CTL. More...
 
cy_en_lin_status_t Cy_LIN_ErrCtl_Disable (LIN_Type *base)
 Disables LIN ERROR CTL. More...
 

Detailed Description

Function Documentation

◆ Cy_LIN_DeInit()

cy_en_lin_status_t Cy_LIN_DeInit ( LIN_CH_Type *  base)

Deinitialization of a LIN module.

This function deinitializes the selected LIN channel.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
Returns
Refer cy_en_lin_status_t
Function Usage
if(CY_LIN_SUCCESS != Cy_LIN_DeInit (LIN0_CH0))
{
/* Insert error handling */
}

◆ Cy_LIN_Init()

cy_en_lin_status_t Cy_LIN_Init ( LIN_CH_Type *  base,
const cy_stc_lin_config_t pstcConfig 
)

Initializes the LIN module.

This function initializes LIN according to the options setup in the passed Config Struct. Several checkings are done before that and an error is returned if invalid Modes are requested.

Precondition
The Application must configure corresponding LIN pins (SIN, SOT) according to requirements and settings of LIN instance. And must set baud rate using SysClk. LIN interface(I/F) has internal fixed oversampling value (16). Therefore, LIN clock / 16 is actual baud rate.
Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
pstcConfigLIN module configuration. See cy_stc_lin_config_t.
Returns
Refer cy_en_lin_status_t
Function Usage
#define LIN_MASTER_CHANNEL LIN0_CH0
#define LIN_SLAVE_CHANNEL LIN0_CH1
const cy_stc_lin_config_t lin_0_ch0_config =
{
.masterMode = true,
.linTransceiverAutoEnable = true,
.breakFieldLength = 13,
.breakDelimiterLength = LIN_BREAK_DILIMITER_LENGTH_4BITS,
.stopBit = LIN_ONE_STOP_BIT,
.filterEnable = true,
};
if(CY_LIN_SUCCESS != Cy_LIN_Init(LIN0_CH0, &lin_0_ch0_config))
{
/* Insert error handling */
}

◆ Cy_LIN_ReadData()

cy_en_lin_status_t Cy_LIN_ReadData ( const LIN_CH_Type *  base,
uint8_t *  data 
)

Reads response data.

Data is read in Bytes. Maximum data length is 8-bytes.

Precondition
Must be run after RX_RESPONSE_DONE.
Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
dataPointer to received data. Must have enough space for current Rx data.
Returns
Refer cy_en_lin_status_t
Function Usage
/* LIN interrupt handler */
/*
* Master Interrupt handler
* Master Sends the header and wait for interrupts.
* If the Interrupt is for Tx Header Done then Header is transferred properly.
* If the interrupt is for Rx Response Done then Master reads the response.
* If the Interrupt is for Tx Response Done then response is transferred properly.
* Handle any Errors if there is an error interrupt.
*/
void lin_master_intHandler(void)
{
uint32_t status;
uint32_t maskStatus;
cy_en_lin_status_t linStatus;
Cy_LIN_GetInterruptMaskedStatus(LIN_MASTER_CHANNEL, &maskStatus);
if ((maskStatus & LIN_INTR_ALL_ERROR_MASK_MASTER) != 0u)
{
/* There are some error */
/* Handle error if needed. */
/* Disable the channel to reset LIN status */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);
/* Re-enable the channel */
Cy_LIN_Enable(LIN_MASTER_CHANNEL);
}
else
{
if(maskStatus & LIN_INTR_TX_HEADER_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE);
}
else if(maskStatus & LIN_INTR_TX_RESPONSE_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus);
}
else if(maskStatus & LIN_INTR_RX_RESPONSE_DONE)
{
memset(dstData, 0, LIN_DATA_LENGTH_MAX*sizeof(dstData[0]));
linStatus = Cy_LIN_ReadData(LIN_MASTER_CHANNEL, dstData);
if(linStatus != CY_LIN_SUCCESS)
{
/* Insert error handling */
}
else
{
status = memcmp(srcData, dstData, (LIN_DATA_LENGTH_MAX*sizeof(dstData[0])));
if (status !=0)
{
/* Insert error handling */
}
}
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus); /* Clear all accepted interrupt. */
}
}
}

◆ Cy_LIN_WriteData()

cy_en_lin_status_t Cy_LIN_WriteData ( LIN_CH_Type *  base,
const uint8_t *  data,
uint8_t  dataLength 
)

Writes response data.

Data is written in Bytes. Maximum data length is 8-bytes.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
dataPointer to response data.
dataLengthData length in bytes.
Returns
Refer cy_en_lin_status_t
Function Usage
/* LIN reception callback */
/*
* Master setCmd function
* Sets the interrupt mask for desired interrupt callback notification.
* Sets the command based on the type of command to be sent.
* Master always sends the header.
*/
void lin_master_setCmd(void)
{
cy_en_lin_status_t linStatus;
/* LIN operation */
linStatus = Cy_LIN_SetInterruptMask(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE | LIN_INTR_TX_RESPONSE_DONE | LIN_INTR_RX_RESPONSE_DONE | LIN_INTR_ALL_ERROR_MASK_SLAVE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetChecksumType(LIN_MASTER_CHANNEL,LIN_CHECKSUM_TYPE_EXTENDED);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetHeader(LIN_MASTER_CHANNEL, master_msgContext[scheduleIdx].id);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetDataLength(LIN_MASTER_CHANNEL, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
if((master_msgContext[scheduleIdx].id == 0x02) || (master_msgContext[scheduleIdx].id == 0x11))
{
linStatus = Cy_LIN_WriteData(LIN_MASTER_CHANNEL, srcData, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_TX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
else
{
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_RX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
}

◆ Cy_LIN_Enable()

cy_en_lin_status_t Cy_LIN_Enable ( LIN_CH_Type *  base)

Enables LIN channel.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
Returns
Refer cy_en_lin_status_t
Function Usage
if(CY_LIN_SUCCESS != Cy_LIN_Enable(LIN0_CH0))
{
/* Insert error handling */
}

◆ Cy_LIN_Disable()

cy_en_lin_status_t Cy_LIN_Disable ( LIN_CH_Type *  base)

Disables LIN channel.

Disabling LIN channel causes clearing of non retained registers. e.g) CMD register, INTR register, STATUS register. This behavior can be used for re-initialization, after error or abort RX operation.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
Returns
Refer cy_en_lin_status_t
Function Usage
if(CY_LIN_SUCCESS != Cy_LIN_Disable(LIN0_CH0))
{
/* Insert error handling */
}

◆ Cy_LIN_SetBreakWakeupFieldLength()

cy_en_lin_status_t Cy_LIN_SetBreakWakeupFieldLength ( LIN_CH_Type *  base,
uint8_t  length 
)

Sets LIN break/wakeup field length.

Normally this interface(I/F) is used for detection of the wakeup pulse.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
lengthBit length of the break/wakeup field.
Returns
Refer cy_en_lin_status_t
Function Usage
{
{0x01, LIN_RX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 8u,},
{0x02, LIN_TX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 8u,},
{0x10, LIN_RX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 1u,},
{0x11, LIN_TX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 1u,},
{0x20, LIN_TX_HEADER, LIN_CHECKSUM_TYPE_EXTENDED, 8u,},
};
uint8_t scheduleIdx = -1;
uint8_t srcData[LIN_DATA_LENGTH_MAX];
uint8_t dstData[LIN_DATA_LENGTH_MAX];
void lin_master_intHandler(void);
/*******************************************************************************
* Function Name: snippet_Cy_LIN_Init
****************************************************************************/
void snippet_Cy_LIN_Init(void)
{
#define LIN_MASTER_CHANNEL LIN0_CH0
#define LIN_SLAVE_CHANNEL LIN0_CH1
const cy_stc_lin_config_t lin_0_ch0_config =
{
.masterMode = true,
.linTransceiverAutoEnable = true,
.breakFieldLength = 13,
.breakDelimiterLength = LIN_BREAK_DILIMITER_LENGTH_4BITS,
.stopBit = LIN_ONE_STOP_BIT,
.filterEnable = true,
};
if(CY_LIN_SUCCESS != Cy_LIN_Init(LIN0_CH0, &lin_0_ch0_config))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_DeInit
****************************************************************************/
void snippet_Cy_LIN_DeInit (void)
{
if(CY_LIN_SUCCESS != Cy_LIN_DeInit (LIN0_CH0))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_Enable
****************************************************************************/
void snippet_Cy_LIN_Enable(void)
{
if(CY_LIN_SUCCESS != Cy_LIN_Enable(LIN0_CH0))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_Disable
****************************************************************************/
void snippet_Cy_LIN_Disable(void)
{
if(CY_LIN_SUCCESS != Cy_LIN_Disable(LIN0_CH0))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetChecksumType
****************************************************************************/
void snippet_Cy_LIN_SetChecksumType(void)
{
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetDataLength
****************************************************************************/
void snippet_Cy_LIN_SetDataLength(void)
{
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetHeader
****************************************************************************/
void snippet_Cy_LIN_SetHeader(void)
{
uint8_t id = 0x01; /* frame identifier of the predefined messages agreed between master and slave. */
if(CY_LIN_SUCCESS != Cy_LIN_SetHeader(LIN0_CH0, id))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetCmd
****************************************************************************/
void snippet_Cy_LIN_SetCmd(void)
{
{
/* Insert error handling */
}
}
/* LIN reception callback */
/*
* Master setCmd function
* Sets the interrupt mask for desired interrupt callback notification.
* Sets the command based on the type of command to be sent.
* Master always sends the header.
*/
void lin_master_setCmd(void)
{
cy_en_lin_status_t linStatus;
/* LIN operation */
linStatus = Cy_LIN_SetInterruptMask(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE | LIN_INTR_TX_RESPONSE_DONE | LIN_INTR_RX_RESPONSE_DONE | LIN_INTR_ALL_ERROR_MASK_SLAVE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetChecksumType(LIN_MASTER_CHANNEL,LIN_CHECKSUM_TYPE_EXTENDED);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetHeader(LIN_MASTER_CHANNEL, master_msgContext[scheduleIdx].id);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetDataLength(LIN_MASTER_CHANNEL, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
if((master_msgContext[scheduleIdx].id == 0x02) || (master_msgContext[scheduleIdx].id == 0x11))
{
linStatus = Cy_LIN_WriteData(LIN_MASTER_CHANNEL, srcData, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_TX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
else
{
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_RX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
}
/* LIN interrupt handler */
/*
* Master Interrupt handler
* Master Sends the header and wait for interrupts.
* If the Interrupt is for Tx Header Done then Header is transferred properly.
* If the interrupt is for Rx Response Done then Master reads the response.
* If the Interrupt is for Tx Response Done then response is transferred properly.
* Handle any Errors if there is an error interrupt.
*/
void lin_master_intHandler(void)
{
uint32_t status;
uint32_t maskStatus;
cy_en_lin_status_t linStatus;
Cy_LIN_GetInterruptMaskedStatus(LIN_MASTER_CHANNEL, &maskStatus);
if ((maskStatus & LIN_INTR_ALL_ERROR_MASK_MASTER) != 0u)
{
/* There are some error */
/* Handle error if needed. */
/* Disable the channel to reset LIN status */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);
/* Re-enable the channel */
Cy_LIN_Enable(LIN_MASTER_CHANNEL);
}
else
{
if(maskStatus & LIN_INTR_TX_HEADER_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE);
}
else if(maskStatus & LIN_INTR_TX_RESPONSE_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus);
}
else if(maskStatus & LIN_INTR_RX_RESPONSE_DONE)
{
memset(dstData, 0, LIN_DATA_LENGTH_MAX*sizeof(dstData[0]));
linStatus = Cy_LIN_ReadData(LIN_MASTER_CHANNEL, dstData);
if(linStatus != CY_LIN_SUCCESS)
{
/* Insert error handling */
}
else
{
status = memcmp(srcData, dstData, (LIN_DATA_LENGTH_MAX*sizeof(dstData[0])));
if (status !=0)
{
/* Insert error handling */
}
}
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus); /* Clear all accepted interrupt. */
}
}
}
/*******************************************************************************
* Function Name: Main
****************************************************************************/
void lin_main(void)
{
/* enable interrupts */
__enable_irq();
uint8_t srcData[LIN_DATA_LENGTH_MAX];
uint8_t dstData[LIN_DATA_LENGTH_MAX];
#define SYSTICK_RELOAD_VAL 4800000UL
#define LIN_MASTER_CHANNEL LIN0_CH0
#define LIN_SLAVE_CHANNEL LIN0_CH1
for (uint8_t i=0; i<LIN_DATA_LENGTH_MAX; i++)
{
srcData[i] = i+1;
}
/* Setup the LIN interrupt */
{
/* Populate the configuration structure */
const cy_stc_sysint_t master_irq_cfg =
{
/* .intrSrc */ lin_interrupts_0_IRQn, /* LIN interrupt number */
/* .intrPriority */ 3UL
};
/* Hook the interrupt service routine and enable the interrupt */
sysStatus = Cy_SysInt_Init(&master_irq_cfg, &lin_master_intHandler);
if(CY_SYSINT_SUCCESS != sysStatus)
{
/* Insert error handling */
}
/* Enable interrupt in NVIC. */
NVIC_EnableIRQ(lin_interrupts_0_IRQn);
}
const cy_stc_lin_config_t lin_0_ch0_config =
{
.masterMode = true,
.linTransceiverAutoEnable = true,
.breakFieldLength = 13,
.breakDelimiterLength = LIN_BREAK_DILIMITER_LENGTH_4BITS,
.stopBit = LIN_ONE_STOP_BIT,
.filterEnable = true,
};
if(CY_LIN_SUCCESS != Cy_LIN_Init(LIN_MASTER_CHANNEL, &lin_0_ch0_config))
{
/* Error processing */
}
/* Enables the configuration changes to set Test mode */
Cy_LIN_EnOut_Enable(LIN_MASTER_CHANNEL);
/* Sets the Test mode configuration */
const cy_stc_lin_test_config_t linTestCfg =
{
/* .chidx */ 0UL, /* channel index */
/* .mode */ 1UL
};
Cy_LIN_TestMode_Enable(LIN0, &linTestCfg);
/* Disables the configuration changes */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);
snippet_Cy_LIN_Init();
snippet_Cy_LIN_Enable();
snippet_Cy_LIN_SetChecksumType();
snippet_Cy_LIN_SetDataLength();
snippet_Cy_LIN_SetHeader();
snippet_Cy_LIN_SetCmd();
snippet_Cy_LIN_Disable();
snippet_Cy_LIN_DeInit();
(void)dstData;
(void)srcData;
}
#else
void lin_main(void)
{
return;
}
#endif /* (CY_IP_MXLIN) */

◆ Cy_LIN_SetDataLength()

cy_en_lin_status_t Cy_LIN_SetDataLength ( LIN_CH_Type *  base,
uint8_t  length 
)

Sets LIN response field data length.

Data is in Bytes and maximum data length is 8-bytes.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
lengthData length in byte
Returns
Refer cy_en_lin_status_t
Function Usage
if(CY_LIN_SUCCESS != Cy_LIN_SetDataLength(LIN0_CH0, LIN_DATA_LENGTH_MAX))
{
/* Insert error handling */
}

◆ Cy_LIN_SetChecksumType()

cy_en_lin_status_t Cy_LIN_SetChecksumType ( LIN_CH_Type *  base,
cy_en_lin_checksum_type_t  type 
)

Sets LIN checksum type setting.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
typeChecksum type. Refer cy_en_lin_checksum_type_t
Returns
Refer cy_en_lin_status_t
Function Usage
{
/* Insert error handling */
}

◆ Cy_LIN_SetCmd()

cy_en_lin_status_t Cy_LIN_SetCmd ( LIN_CH_Type *  base,
uint32_t  command 
)

Sets LIN operation command.

Note
As a normal usage, following combinations are used.
  • Master Header TX only : LIN_CMD_TX_HEADER Header TX & TX response : LIN_CMD_TX_HEADER_TX_RESPONSE Header TX & RX response : LIN_CMD_TX_HEADER_RX_RESPONSE
  • Slave Header RX : LIN_CMD_RX_HEADER_RX_RESPONSE TX response : LIN_CMD_TX_RESPONSE RX response : Already set when header RX As a typical usage, RX response is always set at header RX phase.
  • Wakeup frame : LIN_CMD_TX_WAKEUP Instead of above macro, you can use raw definition LIN_CH_CMD_*_Msk defined in IO header file.
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
commandRequired operation command. Refer LIN Command Type Definition
Returns
Refer cy_en_lin_status_t
Function Usage
{
/* Insert error handling */
}

◆ Cy_LIN_SetHeader()

cy_en_lin_status_t Cy_LIN_SetHeader ( LIN_CH_Type *  base,
uint8_t  id 
)

Sets LIN header for master tx header operation.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
idID value
Returns
Refer cy_en_lin_status_t
Function Usage
uint8_t id = 0x01; /* frame identifier of the predefined messages agreed between master and slave. */
if(CY_LIN_SUCCESS != Cy_LIN_SetHeader(LIN0_CH0, id))
{
/* Insert error handling */
}

◆ Cy_LIN_GetHeader()

cy_en_lin_status_t Cy_LIN_GetHeader ( const LIN_CH_Type *  base,
uint8_t *  id,
uint8_t *  parity 
)

Returns received LIN header.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
idReceived ID value.
parityPointer to received parity value.
Note
Note that parity check is always done by HW automatically.
Returns
Refer cy_en_lin_status_t

◆ Cy_LIN_SetInterruptMask()

cy_en_lin_status_t Cy_LIN_SetInterruptMask ( LIN_CH_Type *  base,
uint32_t  mask 
)

Sets interrupt source to be accepted.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
maskThe mask with the OR of the interrupt source to be accepted. See LIN ALL Interrupt Mask Definition for the set of constants.
Returns
Refer cy_en_lin_status_t
Function Usage
/* LIN reception callback */
/*
* Master setCmd function
* Sets the interrupt mask for desired interrupt callback notification.
* Sets the command based on the type of command to be sent.
* Master always sends the header.
*/
void lin_master_setCmd(void)
{
cy_en_lin_status_t linStatus;
/* LIN operation */
linStatus = Cy_LIN_SetInterruptMask(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE | LIN_INTR_TX_RESPONSE_DONE | LIN_INTR_RX_RESPONSE_DONE | LIN_INTR_ALL_ERROR_MASK_SLAVE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetChecksumType(LIN_MASTER_CHANNEL,LIN_CHECKSUM_TYPE_EXTENDED);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetHeader(LIN_MASTER_CHANNEL, master_msgContext[scheduleIdx].id);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetDataLength(LIN_MASTER_CHANNEL, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
if((master_msgContext[scheduleIdx].id == 0x02) || (master_msgContext[scheduleIdx].id == 0x11))
{
linStatus = Cy_LIN_WriteData(LIN_MASTER_CHANNEL, srcData, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_TX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
else
{
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_RX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
}

◆ Cy_LIN_GetInterruptMask()

cy_en_lin_status_t Cy_LIN_GetInterruptMask ( const LIN_CH_Type *  base,
uint32_t *  mask 
)

Returns interrupt mask setting.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
maskPointer to the mask with the OR of the interrupt source which is masked. See LIN ALL Interrupt Mask Definition for the set of constants.
Returns
Refer cy_en_lin_status_t
Function Usage
/* LIN reception callback */
/*
* Master setCmd function
* Sets the interrupt mask for desired interrupt callback notification.
* Sets the command based on the type of command to be sent.
* Master always sends the header.
*/
void lin_master_setCmd(void)
{
cy_en_lin_status_t linStatus;
/* LIN operation */
linStatus = Cy_LIN_SetInterruptMask(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE | LIN_INTR_TX_RESPONSE_DONE | LIN_INTR_RX_RESPONSE_DONE | LIN_INTR_ALL_ERROR_MASK_SLAVE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetChecksumType(LIN_MASTER_CHANNEL,LIN_CHECKSUM_TYPE_EXTENDED);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetHeader(LIN_MASTER_CHANNEL, master_msgContext[scheduleIdx].id);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetDataLength(LIN_MASTER_CHANNEL, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
if((master_msgContext[scheduleIdx].id == 0x02) || (master_msgContext[scheduleIdx].id == 0x11))
{
linStatus = Cy_LIN_WriteData(LIN_MASTER_CHANNEL, srcData, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_TX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
else
{
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_RX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
}

◆ Cy_LIN_GetInterruptMaskedStatus()

cy_en_lin_status_t Cy_LIN_GetInterruptMaskedStatus ( const LIN_CH_Type *  base,
uint32_t *  status 
)

Returns interrupt masked status.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
statusPointer to the mask with the OR of the interrupt source which occurs. See LIN ALL Interrupt Mask Definition for the set of constants.
Returns
Refer cy_en_lin_status_t
Function Usage
/* LIN interrupt handler */
/*
* Master Interrupt handler
* Master Sends the header and wait for interrupts.
* If the Interrupt is for Tx Header Done then Header is transferred properly.
* If the interrupt is for Rx Response Done then Master reads the response.
* If the Interrupt is for Tx Response Done then response is transferred properly.
* Handle any Errors if there is an error interrupt.
*/
void lin_master_intHandler(void)
{
uint32_t status;
uint32_t maskStatus;
cy_en_lin_status_t linStatus;
Cy_LIN_GetInterruptMaskedStatus(LIN_MASTER_CHANNEL, &maskStatus);
if ((maskStatus & LIN_INTR_ALL_ERROR_MASK_MASTER) != 0u)
{
/* There are some error */
/* Handle error if needed. */
/* Disable the channel to reset LIN status */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);
/* Re-enable the channel */
Cy_LIN_Enable(LIN_MASTER_CHANNEL);
}
else
{
if(maskStatus & LIN_INTR_TX_HEADER_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE);
}
else if(maskStatus & LIN_INTR_TX_RESPONSE_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus);
}
else if(maskStatus & LIN_INTR_RX_RESPONSE_DONE)
{
memset(dstData, 0, LIN_DATA_LENGTH_MAX*sizeof(dstData[0]));
linStatus = Cy_LIN_ReadData(LIN_MASTER_CHANNEL, dstData);
if(linStatus != CY_LIN_SUCCESS)
{
/* Insert error handling */
}
else
{
status = memcmp(srcData, dstData, (LIN_DATA_LENGTH_MAX*sizeof(dstData[0])));
if (status !=0)
{
/* Insert error handling */
}
}
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus); /* Clear all accepted interrupt. */
}
}
}

◆ Cy_LIN_GetInterruptStatus()

cy_en_lin_status_t Cy_LIN_GetInterruptStatus ( const LIN_CH_Type *  base,
uint32_t *  status 
)

Returns interrupt raw status.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
statusPointer to the mask with the OR of the interrupt source which occurs. See LIN ALL Interrupt Mask Definition for the set of constants.
Returns
Refer cy_en_lin_status_t
Function Usage
/* LIN interrupt handler */
/*
* Master Interrupt handler
* Master Sends the header and wait for interrupts.
* If the Interrupt is for Tx Header Done then Header is transferred properly.
* If the interrupt is for Rx Response Done then Master reads the response.
* If the Interrupt is for Tx Response Done then response is transferred properly.
* Handle any Errors if there is an error interrupt.
*/
void lin_master_intHandler(void)
{
uint32_t status;
uint32_t maskStatus;
cy_en_lin_status_t linStatus;
Cy_LIN_GetInterruptMaskedStatus(LIN_MASTER_CHANNEL, &maskStatus);
if ((maskStatus & LIN_INTR_ALL_ERROR_MASK_MASTER) != 0u)
{
/* There are some error */
/* Handle error if needed. */
/* Disable the channel to reset LIN status */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);
/* Re-enable the channel */
Cy_LIN_Enable(LIN_MASTER_CHANNEL);
}
else
{
if(maskStatus & LIN_INTR_TX_HEADER_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE);
}
else if(maskStatus & LIN_INTR_TX_RESPONSE_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus);
}
else if(maskStatus & LIN_INTR_RX_RESPONSE_DONE)
{
memset(dstData, 0, LIN_DATA_LENGTH_MAX*sizeof(dstData[0]));
linStatus = Cy_LIN_ReadData(LIN_MASTER_CHANNEL, dstData);
if(linStatus != CY_LIN_SUCCESS)
{
/* Insert error handling */
}
else
{
status = memcmp(srcData, dstData, (LIN_DATA_LENGTH_MAX*sizeof(dstData[0])));
if (status !=0)
{
/* Insert error handling */
}
}
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus); /* Clear all accepted interrupt. */
}
}
}

◆ Cy_LIN_ClearInterrupt()

cy_en_lin_status_t Cy_LIN_ClearInterrupt ( LIN_CH_Type *  base,
uint32_t  mask 
)

Clears interrupt status.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
maskThe mask with the OR of the interrupt source to be cleared. See LIN ALL Interrupt Mask Definition for the set of constants.
Returns
Refer cy_en_lin_status_t
Function Usage
/* LIN interrupt handler */
/*
* Master Interrupt handler
* Master Sends the header and wait for interrupts.
* If the Interrupt is for Tx Header Done then Header is transferred properly.
* If the interrupt is for Rx Response Done then Master reads the response.
* If the Interrupt is for Tx Response Done then response is transferred properly.
* Handle any Errors if there is an error interrupt.
*/
void lin_master_intHandler(void)
{
uint32_t status;
uint32_t maskStatus;
cy_en_lin_status_t linStatus;
Cy_LIN_GetInterruptMaskedStatus(LIN_MASTER_CHANNEL, &maskStatus);
if ((maskStatus & LIN_INTR_ALL_ERROR_MASK_MASTER) != 0u)
{
/* There are some error */
/* Handle error if needed. */
/* Disable the channel to reset LIN status */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);
/* Re-enable the channel */
Cy_LIN_Enable(LIN_MASTER_CHANNEL);
}
else
{
if(maskStatus & LIN_INTR_TX_HEADER_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE);
}
else if(maskStatus & LIN_INTR_TX_RESPONSE_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus);
}
else if(maskStatus & LIN_INTR_RX_RESPONSE_DONE)
{
memset(dstData, 0, LIN_DATA_LENGTH_MAX*sizeof(dstData[0]));
linStatus = Cy_LIN_ReadData(LIN_MASTER_CHANNEL, dstData);
if(linStatus != CY_LIN_SUCCESS)
{
/* Insert error handling */
}
else
{
status = memcmp(srcData, dstData, (LIN_DATA_LENGTH_MAX*sizeof(dstData[0])));
if (status !=0)
{
/* Insert error handling */
}
}
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus); /* Clear all accepted interrupt. */
}
}
}

◆ Cy_LIN_GetStatus()

cy_en_lin_status_t Cy_LIN_GetStatus ( const LIN_CH_Type *  base,
uint32_t *  status 
)
Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
statusLIN module status.
Returns
Refer cy_en_lin_status_t
Function Usage
/* LIN interrupt handler */
/*
* Master Interrupt handler
* Master Sends the header and wait for interrupts.
* If the Interrupt is for Tx Header Done then Header is transferred properly.
* If the interrupt is for Rx Response Done then Master reads the response.
* If the Interrupt is for Tx Response Done then response is transferred properly.
* Handle any Errors if there is an error interrupt.
*/
void lin_master_intHandler(void)
{
uint32_t status;
uint32_t maskStatus;
cy_en_lin_status_t linStatus;
Cy_LIN_GetInterruptMaskedStatus(LIN_MASTER_CHANNEL, &maskStatus);
if ((maskStatus & LIN_INTR_ALL_ERROR_MASK_MASTER) != 0u)
{
/* There are some error */
/* Handle error if needed. */
/* Disable the channel to reset LIN status */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);
/* Re-enable the channel */
Cy_LIN_Enable(LIN_MASTER_CHANNEL);
}
else
{
if(maskStatus & LIN_INTR_TX_HEADER_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE);
}
else if(maskStatus & LIN_INTR_TX_RESPONSE_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus);
}
else if(maskStatus & LIN_INTR_RX_RESPONSE_DONE)
{
memset(dstData, 0, LIN_DATA_LENGTH_MAX*sizeof(dstData[0]));
linStatus = Cy_LIN_ReadData(LIN_MASTER_CHANNEL, dstData);
if(linStatus != CY_LIN_SUCCESS)
{
/* Insert error handling */
}
else
{
status = memcmp(srcData, dstData, (LIN_DATA_LENGTH_MAX*sizeof(dstData[0])));
if (status !=0)
{
/* Insert error handling */
}
}
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus); /* Clear all accepted interrupt. */
}
}
}

◆ Cy_LIN_EnOut_Enable()

cy_en_lin_status_t Cy_LIN_EnOut_Enable ( LIN_CH_Type *  base)

Enables LIN channel 'en' out.

If linTransceiverAutoEnable in cy_stc_lin_config_t config structure is set to true then transceiver is set automatically and user need not call this function, else user has to enable LIN transceiver manually before sending a message, and disable it after sending the message.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
Returns
Refer cy_en_lin_status_t
Function Usage
if(CY_LIN_SUCCESS != Cy_LIN_Init(LIN_MASTER_CHANNEL, &lin_0_ch0_config))
{
/* Error processing */
}
/* Enables the configuration changes to set Test mode */
Cy_LIN_EnOut_Enable(LIN_MASTER_CHANNEL);
/* Sets the Test mode configuration */
const cy_stc_lin_test_config_t linTestCfg =
{
/* .chidx */ 0UL, /* channel index */
/* .mode */ 1UL
};
Cy_LIN_TestMode_Enable(LIN0, &linTestCfg);
/* Disables the configuration changes */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);

◆ Cy_LIN_EnOut_Disable()

cy_en_lin_status_t Cy_LIN_EnOut_Disable ( LIN_CH_Type *  base)

Disables LIN channel 'en' out.

If linTransceiverAutoEnable in cy_stc_lin_config_t config structure is set to true then transceiver is set automatically and user need not call this function, else user has to enable LIN transceiver manually before sending a message, and disable it after sending the message.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
Returns
Refer cy_en_lin_status_t
Function Usage
{
{0x01, LIN_RX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 8u,},
{0x02, LIN_TX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 8u,},
{0x10, LIN_RX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 1u,},
{0x11, LIN_TX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 1u,},
{0x20, LIN_TX_HEADER, LIN_CHECKSUM_TYPE_EXTENDED, 8u,},
};
uint8_t scheduleIdx = -1;
uint8_t srcData[LIN_DATA_LENGTH_MAX];
uint8_t dstData[LIN_DATA_LENGTH_MAX];
void lin_master_intHandler(void);
/*******************************************************************************
* Function Name: snippet_Cy_LIN_Init
****************************************************************************/
void snippet_Cy_LIN_Init(void)
{
#define LIN_MASTER_CHANNEL LIN0_CH0
#define LIN_SLAVE_CHANNEL LIN0_CH1
const cy_stc_lin_config_t lin_0_ch0_config =
{
.masterMode = true,
.linTransceiverAutoEnable = true,
.breakFieldLength = 13,
.breakDelimiterLength = LIN_BREAK_DILIMITER_LENGTH_4BITS,
.stopBit = LIN_ONE_STOP_BIT,
.filterEnable = true,
};
if(CY_LIN_SUCCESS != Cy_LIN_Init(LIN0_CH0, &lin_0_ch0_config))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_DeInit
****************************************************************************/
void snippet_Cy_LIN_DeInit (void)
{
if(CY_LIN_SUCCESS != Cy_LIN_DeInit (LIN0_CH0))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_Enable
****************************************************************************/
void snippet_Cy_LIN_Enable(void)
{
if(CY_LIN_SUCCESS != Cy_LIN_Enable(LIN0_CH0))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_Disable
****************************************************************************/
void snippet_Cy_LIN_Disable(void)
{
if(CY_LIN_SUCCESS != Cy_LIN_Disable(LIN0_CH0))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetChecksumType
****************************************************************************/
void snippet_Cy_LIN_SetChecksumType(void)
{
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetDataLength
****************************************************************************/
void snippet_Cy_LIN_SetDataLength(void)
{
if(CY_LIN_SUCCESS != Cy_LIN_SetDataLength(LIN0_CH0, LIN_DATA_LENGTH_MAX))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetHeader
****************************************************************************/
void snippet_Cy_LIN_SetHeader(void)
{
uint8_t id = 0x01; /* frame identifier of the predefined messages agreed between master and slave. */
if(CY_LIN_SUCCESS != Cy_LIN_SetHeader(LIN0_CH0, id))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetCmd
****************************************************************************/
void snippet_Cy_LIN_SetCmd(void)
{
{
/* Insert error handling */
}
}
/* LIN reception callback */
/*
* Master setCmd function
* Sets the interrupt mask for desired interrupt callback notification.
* Sets the command based on the type of command to be sent.
* Master always sends the header.
*/
void lin_master_setCmd(void)
{
cy_en_lin_status_t linStatus;
/* LIN operation */
linStatus = Cy_LIN_SetInterruptMask(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE | LIN_INTR_TX_RESPONSE_DONE | LIN_INTR_RX_RESPONSE_DONE | LIN_INTR_ALL_ERROR_MASK_SLAVE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetChecksumType(LIN_MASTER_CHANNEL,LIN_CHECKSUM_TYPE_EXTENDED);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetHeader(LIN_MASTER_CHANNEL, master_msgContext[scheduleIdx].id);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetDataLength(LIN_MASTER_CHANNEL, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
if((master_msgContext[scheduleIdx].id == 0x02) || (master_msgContext[scheduleIdx].id == 0x11))
{
linStatus = Cy_LIN_WriteData(LIN_MASTER_CHANNEL, srcData, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_TX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
else
{
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_RX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
}
/* LIN interrupt handler */
/*
* Master Interrupt handler
* Master Sends the header and wait for interrupts.
* If the Interrupt is for Tx Header Done then Header is transferred properly.
* If the interrupt is for Rx Response Done then Master reads the response.
* If the Interrupt is for Tx Response Done then response is transferred properly.
* Handle any Errors if there is an error interrupt.
*/
void lin_master_intHandler(void)
{
uint32_t status;
uint32_t maskStatus;
cy_en_lin_status_t linStatus;
Cy_LIN_GetInterruptMaskedStatus(LIN_MASTER_CHANNEL, &maskStatus);
if ((maskStatus & LIN_INTR_ALL_ERROR_MASK_MASTER) != 0u)
{
/* There are some error */
/* Handle error if needed. */
/* Disable the channel to reset LIN status */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);
/* Re-enable the channel */
Cy_LIN_Enable(LIN_MASTER_CHANNEL);
}
else
{
if(maskStatus & LIN_INTR_TX_HEADER_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE);
}
else if(maskStatus & LIN_INTR_TX_RESPONSE_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus);
}
else if(maskStatus & LIN_INTR_RX_RESPONSE_DONE)
{
memset(dstData, 0, LIN_DATA_LENGTH_MAX*sizeof(dstData[0]));
linStatus = Cy_LIN_ReadData(LIN_MASTER_CHANNEL, dstData);
if(linStatus != CY_LIN_SUCCESS)
{
/* Insert error handling */
}
else
{
status = memcmp(srcData, dstData, (LIN_DATA_LENGTH_MAX*sizeof(dstData[0])));
if (status !=0)
{
/* Insert error handling */
}
}
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus); /* Clear all accepted interrupt. */
}
}
}
/*******************************************************************************
* Function Name: Main
****************************************************************************/
void lin_main(void)
{
/* enable interrupts */
__enable_irq();
uint8_t srcData[LIN_DATA_LENGTH_MAX];
uint8_t dstData[LIN_DATA_LENGTH_MAX];
#define SYSTICK_RELOAD_VAL 4800000UL
#define LIN_MASTER_CHANNEL LIN0_CH0
#define LIN_SLAVE_CHANNEL LIN0_CH1
for (uint8_t i=0; i<LIN_DATA_LENGTH_MAX; i++)
{
srcData[i] = i+1;
}
/* Setup the LIN interrupt */
{
/* Populate the configuration structure */
const cy_stc_sysint_t master_irq_cfg =
{
/* .intrSrc */ lin_interrupts_0_IRQn, /* LIN interrupt number */
/* .intrPriority */ 3UL
};
/* Hook the interrupt service routine and enable the interrupt */
sysStatus = Cy_SysInt_Init(&master_irq_cfg, &lin_master_intHandler);
if(CY_SYSINT_SUCCESS != sysStatus)
{
/* Insert error handling */
}
/* Enable interrupt in NVIC. */
NVIC_EnableIRQ(lin_interrupts_0_IRQn);
}
const cy_stc_lin_config_t lin_0_ch0_config =
{
.masterMode = true,
.linTransceiverAutoEnable = true,
.breakFieldLength = 13,
.breakDelimiterLength = LIN_BREAK_DILIMITER_LENGTH_4BITS,
.stopBit = LIN_ONE_STOP_BIT,
.filterEnable = true,
};
if(CY_LIN_SUCCESS != Cy_LIN_Init(LIN_MASTER_CHANNEL, &lin_0_ch0_config))
{
/* Error processing */
}
/* Enables the configuration changes to set Test mode */
Cy_LIN_EnOut_Enable(LIN_MASTER_CHANNEL);
/* Sets the Test mode configuration */
const cy_stc_lin_test_config_t linTestCfg =
{
/* .chidx */ 0UL, /* channel index */
/* .mode */ 1UL
};
Cy_LIN_TestMode_Enable(LIN0, &linTestCfg);
/* Disables the configuration changes */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);
snippet_Cy_LIN_Init();
snippet_Cy_LIN_Enable();
snippet_Cy_LIN_SetChecksumType();
snippet_Cy_LIN_SetDataLength();
snippet_Cy_LIN_SetHeader();
snippet_Cy_LIN_SetCmd();
snippet_Cy_LIN_Disable();
snippet_Cy_LIN_DeInit();
(void)dstData;
(void)srcData;
}
#else
void lin_main(void)
{
return;
}
#endif /* (CY_IP_MXLIN) */

◆ Cy_LIN_TestMode_Enable()

cy_en_lin_status_t Cy_LIN_TestMode_Enable ( LIN_Type *  base,
const cy_stc_lin_test_config_t linTestConfig 
)

Enables LIN Testing mode.

This testing functionality simplifies SW development, but may also be used in the field to verify correct channel functionality.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
linTestConfigPointer to Test configuration structure.
Returns
Refer cy_en_lin_status_t
Function Usage
if(CY_LIN_SUCCESS != Cy_LIN_Init(LIN_MASTER_CHANNEL, &lin_0_ch0_config))
{
/* Error processing */
}
/* Enables the configuration changes to set Test mode */
Cy_LIN_EnOut_Enable(LIN_MASTER_CHANNEL);
/* Sets the Test mode configuration */
const cy_stc_lin_test_config_t linTestCfg =
{
/* .chidx */ 0UL, /* channel index */
/* .mode */ 1UL
};
Cy_LIN_TestMode_Enable(LIN0, &linTestCfg);
/* Disables the configuration changes */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);

◆ Cy_LIN_TestMode_Disable()

cy_en_lin_status_t Cy_LIN_TestMode_Disable ( LIN_Type *  base)

Disables LIN Testing mode.

This testing functionality simplifies SW development, but may also be used in the field to verify correct channel functionality.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
Returns
Refer cy_en_lin_status_t

◆ Cy_LIN_ErrCtl_Enable()

cy_en_lin_status_t Cy_LIN_ErrCtl_Enable ( LIN_Type *  base,
cy_stc_lin_test_error_config_t testErrorConfig 
)

Enables LIN ERROR CTL.

Enables HW injected channel transmitter errors. The receiver should detect these errors and report these errors through activation of corresponding interrupt causes.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
testErrorConfigPointer to Test Error configuration structure.
Returns
Refer cy_en_lin_status_t

◆ Cy_LIN_ErrCtl_Disable()

cy_en_lin_status_t Cy_LIN_ErrCtl_Disable ( LIN_Type *  base)

Disables LIN ERROR CTL.

Disables HW injected channel transmitter errors.

Note
Applicable to PSOC4 HVMS/PA only.
Parameters
basePointer to LIN instance channel register
Returns
Refer cy_en_lin_status_t
Function Usage
{
{0x01, LIN_RX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 8u,},
{0x02, LIN_TX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 8u,},
{0x10, LIN_RX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 1u,},
{0x11, LIN_TX_RESPONSE, LIN_CHECKSUM_TYPE_EXTENDED, 1u,},
{0x20, LIN_TX_HEADER, LIN_CHECKSUM_TYPE_EXTENDED, 8u,},
};
uint8_t scheduleIdx = -1;
uint8_t srcData[LIN_DATA_LENGTH_MAX];
uint8_t dstData[LIN_DATA_LENGTH_MAX];
void lin_master_intHandler(void);
/*******************************************************************************
* Function Name: snippet_Cy_LIN_Init
****************************************************************************/
void snippet_Cy_LIN_Init(void)
{
#define LIN_MASTER_CHANNEL LIN0_CH0
#define LIN_SLAVE_CHANNEL LIN0_CH1
const cy_stc_lin_config_t lin_0_ch0_config =
{
.masterMode = true,
.linTransceiverAutoEnable = true,
.breakFieldLength = 13,
.breakDelimiterLength = LIN_BREAK_DILIMITER_LENGTH_4BITS,
.stopBit = LIN_ONE_STOP_BIT,
.filterEnable = true,
};
if(CY_LIN_SUCCESS != Cy_LIN_Init(LIN0_CH0, &lin_0_ch0_config))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_DeInit
****************************************************************************/
void snippet_Cy_LIN_DeInit (void)
{
if(CY_LIN_SUCCESS != Cy_LIN_DeInit (LIN0_CH0))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_Enable
****************************************************************************/
void snippet_Cy_LIN_Enable(void)
{
if(CY_LIN_SUCCESS != Cy_LIN_Enable(LIN0_CH0))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_Disable
****************************************************************************/
void snippet_Cy_LIN_Disable(void)
{
if(CY_LIN_SUCCESS != Cy_LIN_Disable(LIN0_CH0))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetChecksumType
****************************************************************************/
void snippet_Cy_LIN_SetChecksumType(void)
{
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetDataLength
****************************************************************************/
void snippet_Cy_LIN_SetDataLength(void)
{
if(CY_LIN_SUCCESS != Cy_LIN_SetDataLength(LIN0_CH0, LIN_DATA_LENGTH_MAX))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetHeader
****************************************************************************/
void snippet_Cy_LIN_SetHeader(void)
{
uint8_t id = 0x01; /* frame identifier of the predefined messages agreed between master and slave. */
if(CY_LIN_SUCCESS != Cy_LIN_SetHeader(LIN0_CH0, id))
{
/* Insert error handling */
}
}
/*******************************************************************************
* Function Name: snippet_Cy_LIN_SetCmd
****************************************************************************/
void snippet_Cy_LIN_SetCmd(void)
{
{
/* Insert error handling */
}
}
/* LIN reception callback */
/*
* Master setCmd function
* Sets the interrupt mask for desired interrupt callback notification.
* Sets the command based on the type of command to be sent.
* Master always sends the header.
*/
void lin_master_setCmd(void)
{
cy_en_lin_status_t linStatus;
/* LIN operation */
linStatus = Cy_LIN_SetInterruptMask(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE | LIN_INTR_TX_RESPONSE_DONE | LIN_INTR_RX_RESPONSE_DONE | LIN_INTR_ALL_ERROR_MASK_SLAVE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetChecksumType(LIN_MASTER_CHANNEL,LIN_CHECKSUM_TYPE_EXTENDED);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetHeader(LIN_MASTER_CHANNEL, master_msgContext[scheduleIdx].id);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetDataLength(LIN_MASTER_CHANNEL, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
if((master_msgContext[scheduleIdx].id == 0x02) || (master_msgContext[scheduleIdx].id == 0x11))
{
linStatus = Cy_LIN_WriteData(LIN_MASTER_CHANNEL, srcData, LIN_DATA_LENGTH_MAX);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_TX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
else
{
linStatus = Cy_LIN_SetCmd(LIN_MASTER_CHANNEL, LIN_CMD_TX_HEADER_RX_RESPONSE);
if(CY_LIN_SUCCESS != linStatus)
{
/* Insert error handling */
}
}
}
/* LIN interrupt handler */
/*
* Master Interrupt handler
* Master Sends the header and wait for interrupts.
* If the Interrupt is for Tx Header Done then Header is transferred properly.
* If the interrupt is for Rx Response Done then Master reads the response.
* If the Interrupt is for Tx Response Done then response is transferred properly.
* Handle any Errors if there is an error interrupt.
*/
void lin_master_intHandler(void)
{
uint32_t status;
uint32_t maskStatus;
cy_en_lin_status_t linStatus;
Cy_LIN_GetInterruptMaskedStatus(LIN_MASTER_CHANNEL, &maskStatus);
if ((maskStatus & LIN_INTR_ALL_ERROR_MASK_MASTER) != 0u)
{
/* There are some error */
/* Handle error if needed. */
/* Disable the channel to reset LIN status */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);
/* Re-enable the channel */
Cy_LIN_Enable(LIN_MASTER_CHANNEL);
}
else
{
if(maskStatus & LIN_INTR_TX_HEADER_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, LIN_INTR_TX_HEADER_DONE);
}
else if(maskStatus & LIN_INTR_TX_RESPONSE_DONE)
{
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus);
}
else if(maskStatus & LIN_INTR_RX_RESPONSE_DONE)
{
memset(dstData, 0, LIN_DATA_LENGTH_MAX*sizeof(dstData[0]));
linStatus = Cy_LIN_ReadData(LIN_MASTER_CHANNEL, dstData);
if(linStatus != CY_LIN_SUCCESS)
{
/* Insert error handling */
}
else
{
status = memcmp(srcData, dstData, (LIN_DATA_LENGTH_MAX*sizeof(dstData[0])));
if (status !=0)
{
/* Insert error handling */
}
}
Cy_LIN_ClearInterrupt(LIN_MASTER_CHANNEL, maskStatus); /* Clear all accepted interrupt. */
}
}
}
/*******************************************************************************
* Function Name: Main
****************************************************************************/
void lin_main(void)
{
/* enable interrupts */
__enable_irq();
uint8_t srcData[LIN_DATA_LENGTH_MAX];
uint8_t dstData[LIN_DATA_LENGTH_MAX];
#define SYSTICK_RELOAD_VAL 4800000UL
#define LIN_MASTER_CHANNEL LIN0_CH0
#define LIN_SLAVE_CHANNEL LIN0_CH1
for (uint8_t i=0; i<LIN_DATA_LENGTH_MAX; i++)
{
srcData[i] = i+1;
}
/* Setup the LIN interrupt */
{
/* Populate the configuration structure */
const cy_stc_sysint_t master_irq_cfg =
{
/* .intrSrc */ lin_interrupts_0_IRQn, /* LIN interrupt number */
/* .intrPriority */ 3UL
};
/* Hook the interrupt service routine and enable the interrupt */
sysStatus = Cy_SysInt_Init(&master_irq_cfg, &lin_master_intHandler);
if(CY_SYSINT_SUCCESS != sysStatus)
{
/* Insert error handling */
}
/* Enable interrupt in NVIC. */
NVIC_EnableIRQ(lin_interrupts_0_IRQn);
}
const cy_stc_lin_config_t lin_0_ch0_config =
{
.masterMode = true,
.linTransceiverAutoEnable = true,
.breakFieldLength = 13,
.breakDelimiterLength = LIN_BREAK_DILIMITER_LENGTH_4BITS,
.stopBit = LIN_ONE_STOP_BIT,
.filterEnable = true,
};
if(CY_LIN_SUCCESS != Cy_LIN_Init(LIN_MASTER_CHANNEL, &lin_0_ch0_config))
{
/* Error processing */
}
/* Enables the configuration changes to set Test mode */
Cy_LIN_EnOut_Enable(LIN_MASTER_CHANNEL);
/* Sets the Test mode configuration */
const cy_stc_lin_test_config_t linTestCfg =
{
/* .chidx */ 0UL, /* channel index */
/* .mode */ 1UL
};
Cy_LIN_TestMode_Enable(LIN0, &linTestCfg);
/* Disables the configuration changes */
Cy_LIN_Disable(LIN_MASTER_CHANNEL);
snippet_Cy_LIN_Init();
snippet_Cy_LIN_Enable();
snippet_Cy_LIN_SetChecksumType();
snippet_Cy_LIN_SetDataLength();
snippet_Cy_LIN_SetHeader();
snippet_Cy_LIN_SetCmd();
snippet_Cy_LIN_Disable();
snippet_Cy_LIN_DeInit();
(void)dstData;
(void)srcData;
}
#else
void lin_main(void)
{
return;
}
#endif /* (CY_IP_MXLIN) */