Handle a transaction

Informative

How to answer a header and complete a response. Binding rules: CHI-LIN-MUST-05, CHI-LIN-MUST-06, CHI-LIN-MUST-08CHI-LIN-MUST-13 in Lin — Requirements.

Decide the reaction on the header

Every received header is reported through LinIf_OnHeader. The driver fills in the pid and its internal sduPtr buffer; you fill in how to react:

void LinIf_OnHeader(uint8 channelId, Lin_PduInfoType *pduInfoPtr)
{
    switch (pduInfoPtr->pid) {
    case 0x30u:                              /* we send this frame's response */
        pduInfoPtr->reaction = LIN_REACTION_TX;
        pduInfoPtr->cs       = LIN_CS_ENHANCED;
        pduInfoPtr->dl       = 4u;
        /* write the response bytes into the driver's buffer, byte 0 first */
        pduInfoPtr->sduPtr[0] = 0x11u; /* ... */
        break;
    case 0x31u:                              /* we consume this frame's response */
        pduInfoPtr->reaction = LIN_REACTION_RX;
        pduInfoPtr->cs       = LIN_CS_CLASSIC;
        pduInfoPtr->dl       = 8u;
        break;
    default:
        pduInfoPtr->reaction = LIN_REACTION_IGNORE;
        break;
    }
}

Complete the response

The driver then notifies you when the response finishes:

void LinIf_OnReception(uint8 channelId, uint8 *sduPtr)
{
    /* RX reaction completed — sduPtr holds the received bytes (byte 0 first). */
    /* Consume them BEFORE returning; the buffer is not valid afterwards. */
}

void LinIf_OnTransmission(uint8 channelId)
{
    /* TX reaction completed successfully. */
}

void LinIf_OnError(uint8 channelId, Lin_ErrorType error)
{
    /* checksum, framing, PID-parity, no-response, ... — see reference/errors */
}

Servicing events

  • Interrupt channels: the driver calls these back from Lin_Interrupt; nothing to schedule.

  • Polling channels: you must call Lin_PollFunction cyclically, or the callbacks never fire.

Note

Data consistency. Data handed to LinIf_OnReception (and the sduPtr buffer in LinIf_OnHeader) is valid only until the callback returns (CHI-LIN-MUST-09). Copy anything you need to keep.