stm32/fdcan: use array indexes when accessing RX/TX FIFO
This commit is contained in:
parent
34baf47307
commit
dd8408a973
@ -2354,37 +2354,40 @@ static int fdcan_send(FAR struct can_dev_s *dev, FAR struct can_msg_s *msg)
|
||||
* Transfer message ID (ID) - Value from message structure
|
||||
* Remote Transmission Request (RTR) - Value from message structure
|
||||
* Extended Identifier (XTD) - Depends on configuration.
|
||||
* Error state indicator (ESI) - ESI bit in CAN FD
|
||||
*
|
||||
* Format word T1:
|
||||
* Data Length Code (DLC) - Value from message structure
|
||||
* Bit Rate Switch (BRS) - Bit rate switching for CAN FD
|
||||
* FD format (FDF) - Frame transmited in CAN FD format
|
||||
* Event FIFO Control (EFC) - Do not store events.
|
||||
* Message Marker (MM) - Always zero
|
||||
*/
|
||||
|
||||
txbuffer[0] = 0;
|
||||
txbuffer[1] = 0;
|
||||
|
||||
#ifdef CONFIG_CAN_EXTID
|
||||
if (msg->cm_hdr.ch_extid)
|
||||
{
|
||||
DEBUGASSERT(msg->cm_hdr.ch_id <= CAN_MAX_EXTMSGID);
|
||||
|
||||
regval = BUFFER_R0_EXTID(msg->cm_hdr.ch_id) | BUFFER_R0_XTD;
|
||||
txbuffer[0] |= BUFFER_R0_EXTID(msg->cm_hdr.ch_id) | BUFFER_R0_XTD;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
DEBUGASSERT(msg->cm_hdr.ch_id <= CAN_MAX_STDMSGID);
|
||||
|
||||
regval = BUFFER_R0_STDID(msg->cm_hdr.ch_id);
|
||||
txbuffer[0] |= BUFFER_R0_STDID(msg->cm_hdr.ch_id);
|
||||
}
|
||||
|
||||
if (msg->cm_hdr.ch_rtr)
|
||||
{
|
||||
regval |= BUFFER_R0_RTR;
|
||||
txbuffer[0] |= BUFFER_R0_RTR;
|
||||
}
|
||||
|
||||
txbuffer[0] = regval;
|
||||
|
||||
/* Format word T1:
|
||||
* Data Length Code (DLC) - Value from message structure
|
||||
* Event FIFO Control (EFC) - Do not store events.
|
||||
* Message Marker (MM) - Always zero
|
||||
*/
|
||||
|
||||
txbuffer[1] = BUFFER_R1_DLC(msg->cm_hdr.ch_dlc);
|
||||
txbuffer[1] |= BUFFER_R1_DLC(msg->cm_hdr.ch_dlc);
|
||||
|
||||
/* Followed by the amount of data corresponding to the DLC (T2..) */
|
||||
|
||||
@ -2773,16 +2776,13 @@ static void fdcan_receive(FAR struct can_dev_s *dev,
|
||||
unsigned long nwords)
|
||||
{
|
||||
struct can_hdr_s hdr;
|
||||
uint32_t regval = 0;
|
||||
int ret = 0;
|
||||
|
||||
fdcan_dumprxregs(dev->cd_priv, "Before receive");
|
||||
|
||||
/* Format the CAN header */
|
||||
|
||||
/* Work R0 contains the CAN ID */
|
||||
|
||||
regval = *rxbuffer++;
|
||||
/* Word R0 contains the CAN ID */
|
||||
|
||||
#ifdef CONFIG_CAN_ERRORS
|
||||
hdr.ch_error = 0;
|
||||
@ -2791,46 +2791,46 @@ static void fdcan_receive(FAR struct can_dev_s *dev,
|
||||
|
||||
/* Extract the RTR bit */
|
||||
|
||||
hdr.ch_rtr = ((regval & BUFFER_R0_RTR) != 0);
|
||||
hdr.ch_rtr = ((rxbuffer[0] & BUFFER_R0_RTR) != 0);
|
||||
|
||||
#ifdef CONFIG_CAN_EXTID
|
||||
if ((regval & BUFFER_R0_XTD) != 0)
|
||||
if ((rxbuffer[0] & BUFFER_R0_XTD) != 0)
|
||||
{
|
||||
/* Save the extended ID of the newly received message */
|
||||
|
||||
hdr.ch_id = (regval & BUFFER_R0_EXTID_MASK) >>
|
||||
hdr.ch_id = (rxbuffer[0] & BUFFER_R0_EXTID_MASK) >>
|
||||
BUFFER_R0_EXTID_SHIFT;
|
||||
hdr.ch_extid = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hdr.ch_id = (regval & BUFFER_R0_STDID_MASK) >>
|
||||
hdr.ch_id = (rxbuffer[0] & BUFFER_R0_STDID_MASK) >>
|
||||
BUFFER_R0_STDID_SHIFT;
|
||||
hdr.ch_extid = 0;
|
||||
}
|
||||
|
||||
#else
|
||||
if ((regval & BUFFER_R0_XTD) != 0)
|
||||
if ((rxbuffer[0] & BUFFER_R0_XTD) != 0)
|
||||
{
|
||||
/* Drop any messages with extended IDs */
|
||||
|
||||
canerr("ERROR: Received message with extended identifier. Dropped\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Save the standard ID of the newly received message */
|
||||
|
||||
hdr.ch_id = (regval & BUFFER_R0_STDID_MASK) >> BUFFER_R0_STDID_SHIFT;
|
||||
hdr.ch_id = (rxbuffer[0] & BUFFER_R0_STDID_MASK) >> BUFFER_R0_STDID_SHIFT;
|
||||
#endif
|
||||
|
||||
/* Word R1 contains the DLC and timestamp */
|
||||
|
||||
regval = *rxbuffer++;
|
||||
|
||||
hdr.ch_dlc = (regval & BUFFER_R1_DLC_MASK) >> BUFFER_R1_DLC_SHIFT;
|
||||
hdr.ch_dlc = (rxbuffer[1] & BUFFER_R1_DLC_MASK) >> BUFFER_R1_DLC_SHIFT;
|
||||
|
||||
/* And provide the CAN message to the upper half logic */
|
||||
|
||||
ret = can_receive(dev, &hdr, (FAR uint8_t *)rxbuffer);
|
||||
ret = can_receive(dev, &hdr, (FAR uint8_t *)&rxbuffer[2]);
|
||||
if (ret < 0)
|
||||
{
|
||||
canerr("ERROR: can_receive failed: %d\n", ret);
|
||||
|
@ -1716,36 +1716,39 @@ static int fdcan_send(FAR struct stm32_fdcan_s *priv)
|
||||
* Transfer message ID (ID) - Value from message structure
|
||||
* Remote Transmission Request (RTR) - Value from message structure
|
||||
* Extended Identifier (XTD) - Depends on configuration.
|
||||
* Error state indicator (ESI) - ESI bit in CAN FD
|
||||
*
|
||||
* Format word T1:
|
||||
* Data Length Code (DLC) - Value from message structure
|
||||
* Bit Rate Switch (BRS) - Bit rate switching for CAN FD
|
||||
* FD format (FDF) - Frame transmited in CAN FD format
|
||||
* Event FIFO Control (EFC) - Do not store events.
|
||||
* Message Marker (MM) - Always zero
|
||||
*/
|
||||
|
||||
txbuffer[0] = 0;
|
||||
txbuffer[1] = 0;
|
||||
|
||||
#ifdef CONFIG_NET_CAN_EXTID
|
||||
if (frame->can_id & CAN_EFF_FLAG)
|
||||
{
|
||||
DEBUGASSERT(frame->can_id < (1 << 29));
|
||||
|
||||
regval = BUFFER_R0_EXTID(frame->can_id) | BUFFER_R0_XTD;
|
||||
txbuffer[0] |= BUFFER_R0_EXTID(frame->can_id) | BUFFER_R0_XTD;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
DEBUGASSERT(frame->can_id < (1 << 11));
|
||||
|
||||
regval = BUFFER_R0_STDID(frame->can_id);
|
||||
txbuffer[0] |= BUFFER_R0_STDID(frame->can_id);
|
||||
}
|
||||
|
||||
if (frame->can_id & CAN_RTR_FLAG)
|
||||
{
|
||||
regval |= BUFFER_R0_RTR;
|
||||
txbuffer[0] |= BUFFER_R0_RTR;
|
||||
}
|
||||
|
||||
txbuffer[0] = regval;
|
||||
|
||||
/* Format word T1:
|
||||
* Data Length Code (DLC) - Value from message structure
|
||||
* Event FIFO Control (EFC) - Do not store events.
|
||||
* Message Marker (MM) - Always zero
|
||||
*/
|
||||
|
||||
txbuffer[1] = BUFFER_R1_DLC(frame->can_dlc);
|
||||
|
||||
/* Followed by the amount of data corresponding to the DLC (T2..) */
|
||||
@ -2392,40 +2395,37 @@ static void fdcan_receive(FAR struct stm32_fdcan_s *priv,
|
||||
unsigned long nwords)
|
||||
{
|
||||
FAR struct can_frame *frame = (struct can_frame *)priv->rxdesc;
|
||||
uint32_t regval = 0;
|
||||
|
||||
fdcan_dumprxregs(dev->cd_priv, "Before receive");
|
||||
|
||||
/* Format the CAN header */
|
||||
|
||||
/* Work R0 contains the CAN ID */
|
||||
|
||||
regval = *rxbuffer++;
|
||||
/* Word R0 contains the CAN ID */
|
||||
|
||||
/* Extract the RTR bit */
|
||||
|
||||
if ((regval & BUFFER_R0_RTR) != 0)
|
||||
if ((rxbuffer[0] & BUFFER_R0_RTR) != 0)
|
||||
{
|
||||
frame->can_id |= CAN_RTR_FLAG;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_CAN_EXTID
|
||||
if ((regval & BUFFER_R0_XTD) != 0)
|
||||
if ((rxbuffer[0] & BUFFER_R0_XTD) != 0)
|
||||
{
|
||||
/* Save the extended ID of the newly received message */
|
||||
|
||||
frame->can_id = (regval & BUFFER_R0_EXTID_MASK) >>
|
||||
frame->can_id = (rxbuffer[0] & BUFFER_R0_EXTID_MASK) >>
|
||||
BUFFER_R0_EXTID_SHIFT;
|
||||
frame->can_id |= CAN_EFF_FLAG;
|
||||
}
|
||||
else
|
||||
{
|
||||
frame->can_id = (regval & BUFFER_R0_STDID_MASK) >>
|
||||
frame->can_id = (rxbuffer[0] & BUFFER_R0_STDID_MASK) >>
|
||||
BUFFER_R0_STDID_SHIFT;
|
||||
frame->can_id &= ~CAN_EFF_FLAG;
|
||||
}
|
||||
#else
|
||||
if ((regval & BUFFER_R0_XTD) != 0)
|
||||
if ((rxbuffer[0] & BUFFER_R0_XTD) != 0)
|
||||
{
|
||||
/* Drop any messages with extended IDs */
|
||||
|
||||
@ -2434,18 +2434,16 @@ static void fdcan_receive(FAR struct stm32_fdcan_s *priv,
|
||||
|
||||
/* Save the standard ID of the newly received message */
|
||||
|
||||
frame->can_id = (regval & BUFFER_R0_STDID_MASK) >> BUFFER_R0_STDID_SHIFT;
|
||||
frame->can_id = (rxbuffer[0] & BUFFER_R0_STDID_MASK) >> BUFFER_R0_STDID_SHIFT;
|
||||
#endif
|
||||
|
||||
/* Word R1 contains the DLC and timestamp */
|
||||
|
||||
regval = *rxbuffer++;
|
||||
|
||||
frame->can_dlc = (regval & BUFFER_R1_DLC_MASK) >> BUFFER_R1_DLC_SHIFT;
|
||||
frame->can_dlc = (rxbuffer[1] & BUFFER_R1_DLC_MASK) >> BUFFER_R1_DLC_SHIFT;
|
||||
|
||||
/* Save the message data */
|
||||
|
||||
memcpy(frame->data, (void *)rxbuffer, frame->can_dlc);
|
||||
memcpy(frame->data, (void *)&rxbuffer[2], frame->can_dlc);
|
||||
|
||||
/* Copy the buffer pointer to priv->dev.. Set amount of data
|
||||
* in priv->dev.d_len
|
||||
|
Loading…
Reference in New Issue
Block a user