![]() |
Block diagram of message receiving in HAL in relation to HLL was presented in the picture below.
Mechanism of message reception starts inside of CAN controller. When CAN controller of particular node receives a message, firstly checks correctness of ID (placed within arbitration field) using MASK and FILTER. MCP2515 chip contains up to 7 filters, however only one is used for purpose of PDCP. Afterwards, mechanism of external interrupt is triggered by pulling external interrupt pin of microcontroller to low. Microcontroller is configured to call interrupt routine whenever falling edge on the pin is noticed. Within handler designed software checks source of interrupt - ready transmitting buffer(s), full receiving buffer(s) or some error. Information about all events is saved in special flags.
Moreover every full receiving buffer interrupt triggers software interrupt by calling function triggerSoftwareInterrupt() with argument: TRIGGER_RECEIVING. Because interrupts are swiched-off within interrupt handlers, so just after completing interrupt from CAN controller, message should be handled.
Firstly, function hll_msg_alloc() is called to get free pointer for the received message. Secondly, transfer of id, message length and data is executed using function mcp2515TransmitData() and inside transmitSpi(). Just after transfer, individual elements of the message are assigned to particular fields pointed by mentioned pointer. This solution allows to avoid having buffers inside of HAL and increase speed of data exchange between HAL and HLL of PDCP and upper layers. If data transfer is completed, HAL calls function hll_msg_commit() with the pointer as argument, which allows HLL to process data. Just after that clearInterruptFlag() is called with the flag of the receiving buffer which received the message. From the moment buffer is allowed to overwrite internal receiving buffer.
Message is processed in HLL.
To be filled by AN.