The foxBMS secondary mcu API documentation
can.h File Reference

Header for the driver for the CAN module. More...

#include "can_cfg.h"
Include dependency graph for can.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  CAN_ERROR
 
struct  CAN_RX_BUFFERELEMENT
 
struct  CAN_TX_BUFFERELEMENT
 
struct  CAN_RX_BUFFER
 
struct  CAN_TX_BUFFER
 

Macros

#define CAN0_USE_TX_BUFFER   CAN0_USE_TRANSMIT_BUFFER
 
#define CAN0_USE_RX_BUFFER   CAN0_USE_RECEIVE_BUFFER
 
#define CAN0_TX_BUFFER_LENGTH   CAN0_TRANSMIT_BUFFER_LENGTH
 
#define CAN0_RX_BUFFER_LENGTH   CAN0_RECEIVE_BUFFER_LENGTH
 
#define CAN1_USE_TX_BUFFER   CAN1_USE_TRANSMIT_BUFFER
 
#define CAN1_USE_RX_BUFFER   CAN1_USE_RECEIVE_BUFFER
 
#define CAN1_TX_BUFFER_LENGTH   CAN1_TRANSMIT_BUFFER_LENGTH
 
#define CAN1_RX_BUFFER_LENGTH   CAN1_RECEIVE_BUFFER_LENGTH
 

Typedefs

typedef struct CAN_ERROR CAN_ERROR_s
 
typedef struct CAN_RX_BUFFERELEMENT CAN_RX_BUFFERELEMENT_s
 
typedef struct CAN_TX_BUFFERELEMENT CAN_TX_BUFFERELEMENT_s
 
typedef struct CAN_RX_BUFFER CAN_RX_BUFFER_s
 
typedef struct CAN_TX_BUFFER CAN_TX_BUFFER_s
 

Enumerations

enum  CAN_ErrorTypeDef_e {
  CAN_ERROR_NONE = HAL_CAN_ERROR_NONE, CAN_ERROR_EWG = HAL_CAN_ERROR_EWG, CAN_ERROR_EPV = HAL_CAN_ERROR_EPV, CAN_ERROR_BOF = HAL_CAN_ERROR_BOF,
  CAN_ERROR_STF = HAL_CAN_ERROR_STF, CAN_ERROR_FOR = HAL_CAN_ERROR_FOR, CAN_ERROR_ACK = HAL_CAN_ERROR_ACK, CAN_ERROR_BR = HAL_CAN_ERROR_BR,
  CAN_ERROR_BD = HAL_CAN_ERROR_BD, CAN_ERROR_CRC = HAL_CAN_ERROR_CRC
}
 
enum  CAN_NodeTypeDef_e { CAN_NODE1 = 0, CAN_NODE0 = 1 }
 

Functions

uint32_t CAN_Init (void)
 Initializes CAN settings and message filtering. More...
 
void CAN_TX_IRQHandler (CAN_HandleTypeDef *ptrHcan)
 Handles CAN TX interrupt request. More...
 
void CAN_RX_IRQHandler (CAN_NodeTypeDef_e canNode, CAN_HandleTypeDef *ptrHcan)
 Handles CAN RX interrupt request. More...
 
void CAN_Error_IRQHandler (CAN_NodeTypeDef_e canNode, CAN_HandleTypeDef *ptrHcan)
 Handles CAN error interrupt request. More...
 
STD_RETURN_TYPE_e CAN_TxMsg (CAN_NodeTypeDef_e canNode, uint32_t msgID, uint8_t *ptrMsgData, uint32_t msgLength, uint32_t RTR)
 Transmits message directly on the CAN bus. More...
 
STD_RETURN_TYPE_e CAN_Send (CAN_NodeTypeDef_e canNode, uint32_t msgID, uint8_t *ptrMsgData, uint32_t msgLength, uint32_t RTR)
 Add message to transmit buffer, message will be transmitted shortly after. More...
 
STD_RETURN_TYPE_e CAN_TxMsgBuffer (CAN_NodeTypeDef_e canNode)
 Transmits a can message from transmit buffer. More...
 
STD_RETURN_TYPE_e CAN_ReceiveBuffer (CAN_NodeTypeDef_e canNode, Can_PduType *msg)
 Reads a can message from RxBuffer. More...
 
void CAN_SetSleepMode (CAN_NodeTypeDef_e canNode)
 Set CAN to sleep mode. More...
 
void CAN_WakeUp (CAN_NodeTypeDef_e canNode)
 Wake CAN up from sleep mode. More...
 

Variables

uint8_t canNode0_listenonly_mode
 CAN listen only transceiver mode of CAN node 0. More...
 
uint8_t canNode1_listenonly_mode
 CAN listen only transceiver mode of CAN node 1. More...
 

Detailed Description

Header for the driver for the CAN module.

BSD 3-Clause License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

We kindly request you to use one or more of the following phrases to refer to foxBMS in your hardware, software, documentation or advertising materials:

″This product uses parts of foxBMS®″

″This product includes parts of foxBMS®″

″This product is derived from foxBMS®″

Author
foxBMS Team
Date
12.07.2015 (date of creation)
Module-prefix CAN

Provides the interfaces for initialization, receive and transmit handling

Macro Definition Documentation

◆ CAN0_RX_BUFFER_LENGTH

#define CAN0_RX_BUFFER_LENGTH   CAN0_RECEIVE_BUFFER_LENGTH

◆ CAN0_TX_BUFFER_LENGTH

#define CAN0_TX_BUFFER_LENGTH   CAN0_TRANSMIT_BUFFER_LENGTH

◆ CAN0_USE_RX_BUFFER

#define CAN0_USE_RX_BUFFER   CAN0_USE_RECEIVE_BUFFER

◆ CAN0_USE_TX_BUFFER

#define CAN0_USE_TX_BUFFER   CAN0_USE_TRANSMIT_BUFFER

◆ CAN1_RX_BUFFER_LENGTH

#define CAN1_RX_BUFFER_LENGTH   CAN1_RECEIVE_BUFFER_LENGTH

◆ CAN1_TX_BUFFER_LENGTH

#define CAN1_TX_BUFFER_LENGTH   CAN1_TRANSMIT_BUFFER_LENGTH

◆ CAN1_USE_RX_BUFFER

#define CAN1_USE_RX_BUFFER   CAN1_USE_RECEIVE_BUFFER

◆ CAN1_USE_TX_BUFFER

#define CAN1_USE_TX_BUFFER   CAN1_USE_TRANSMIT_BUFFER

Typedef Documentation

◆ CAN_ERROR_s

typedef struct CAN_ERROR CAN_ERROR_s

◆ CAN_RX_BUFFER_s

◆ CAN_RX_BUFFERELEMENT_s

◆ CAN_TX_BUFFER_s

◆ CAN_TX_BUFFERELEMENT_s

Enumeration Type Documentation

◆ CAN_ErrorTypeDef_e

Enumerator
CAN_ERROR_NONE 

No error

CAN_ERROR_EWG 

EWG error

CAN_ERROR_EPV 

EPV error

CAN_ERROR_BOF 

BOF error

CAN_ERROR_STF 

Stuff error

CAN_ERROR_FOR 

Form error

CAN_ERROR_ACK 

Acknowledgment error

CAN_ERROR_BR 

Bit recessive

CAN_ERROR_BD 

LEC dominant

CAN_ERROR_CRC 

LEC transfer error

◆ CAN_NodeTypeDef_e

Enumerator
CAN_NODE1 
CAN_NODE0 

Function Documentation

◆ CAN_Error_IRQHandler()

void CAN_Error_IRQHandler ( CAN_NodeTypeDef_e  canNode,
CAN_HandleTypeDef *  ptrHcan 
)

Handles CAN error interrupt request.

Parameters
canNode
ptrHcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
None

◆ CAN_Init()

uint32_t CAN_Init ( void  )

Initializes CAN settings and message filtering.

Return values
0if initialization successful, otherwise errorcode
Here is the call graph for this function:

◆ CAN_ReceiveBuffer()

STD_RETURN_TYPE_e CAN_ReceiveBuffer ( CAN_NodeTypeDef_e  canNode,
Can_PduType *  msg 
)

Reads a can message from RxBuffer.

Parameters
canNodecanNode on which a message has been received
msgmessage that has been received
Return values
E_OKif reception successful, if buffer empty or invalid pointer E_NOT_OK

◆ CAN_RX_IRQHandler()

void CAN_RX_IRQHandler ( CAN_NodeTypeDef_e  canNode,
CAN_HandleTypeDef *  ptrHcan 
)

Handles CAN RX interrupt request.

Parameters
canNodecanNode that received a message
ptrHcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
None

◆ CAN_Send()

STD_RETURN_TYPE_e CAN_Send ( CAN_NodeTypeDef_e  canNode,
uint32_t  msgID,
uint8_t *  ptrMsgData,
uint32_t  msgLength,
uint32_t  RTR 
)

Add message to transmit buffer, message will be transmitted shortly after.

---------------------— IMPORTANT!!!! -----------------------------— Make sure that this function is not interrupted by the operating system during its execution.

Parameters
canNodecanNode on which the message shall be transmitted
msgIDID of the message that will be transmitted
ptrMsgDatapointer to a uint8_t array that contains the message that will be transmitted
msgLengthlength of the message that will be transmitted This parameter can be a value of CAN_identifier_type.
RTRSpecifies the type of frame for the message that will be transmitted. This parameter can be a value of CAN_remote_transmission_request
Return values
E_OKif successful, E_NOT_OK if buffer is full or error occurred

◆ CAN_SetSleepMode()

void CAN_SetSleepMode ( CAN_NodeTypeDef_e  canNode)

Set CAN to sleep mode.

Parameters
canNodecanNode which shall be put to sleep mode
Return values
none(void)

◆ CAN_TX_IRQHandler()

void CAN_TX_IRQHandler ( CAN_HandleTypeDef *  ptrHcan)

Handles CAN TX interrupt request.

Parameters
ptrHcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
none(void)

◆ CAN_TxMsg()

STD_RETURN_TYPE_e CAN_TxMsg ( CAN_NodeTypeDef_e  canNode,
uint32_t  msgID,
uint8_t *  ptrMsgData,
uint32_t  msgLength,
uint32_t  RTR 
)

Transmits message directly on the CAN bus.

Parameters
canNodecanNode on which the message shall be transmitted
msgIDID of the message that will be transmitted
ptrMsgDatapointer to the data that shall be transmitted
msgLengthSpecifies the data length
RTRSpecifies the type of frame for the message that will be transmitted.
Return values
E_OKif transmission successful, otherwise E_NOT_OK

◆ CAN_TxMsgBuffer()

STD_RETURN_TYPE_e CAN_TxMsgBuffer ( CAN_NodeTypeDef_e  canNode)

Transmits a can message from transmit buffer.

---------------------— IMPORTANT!!!! -----------------------------— Make sure that this function is not interrupted by the operating system during its execution.

Parameters
canNodecanNode on which the message shall be transmitted
Return values
E_OKif transmission successful, otherwise E_NOT_OK

◆ CAN_WakeUp()

void CAN_WakeUp ( CAN_NodeTypeDef_e  canNode)

Wake CAN up from sleep mode.

Parameters
canNodecanNode which shall be waken up from sleep mode
Return values
none.

Variable Documentation

◆ canNode0_listenonly_mode

uint8_t canNode0_listenonly_mode

CAN listen only transceiver mode of CAN node 0.

◆ canNode1_listenonly_mode

uint8_t canNode1_listenonly_mode

CAN listen only transceiver mode of CAN node 1.