49 #define MCR_DBF ((uint32_t)0x00010000) 52 #define TMIDxR_TXRQ ((uint32_t)0x00000001) 55 #define FMR_FINIT ((uint32_t)0x00000001) 58 #define INAK_TIMEOUT ((uint32_t)0x0000FFFF) 60 #define SLAK_TIMEOUT ((uint32_t)0x0000FFFF) 65 #define CAN_FLAGS_TSR ((uint32_t)0x08000000) 67 #define CAN_FLAGS_RF1R ((uint32_t)0x04000000) 69 #define CAN_FLAGS_RF0R ((uint32_t)0x02000000) 71 #define CAN_FLAGS_MSR ((uint32_t)0x01000000) 73 #define CAN_FLAGS_ESR ((uint32_t)0x00F00000) 76 #define CAN_TXMAILBOX_0 ((uint8_t)0x00) 77 #define CAN_TXMAILBOX_1 ((uint8_t)0x01) 78 #define CAN_TXMAILBOX_2 ((uint8_t)0x02) 82 #define CAN_MODE_MASK ((uint32_t) 0x00000003) 157 uint32_t wait_ack = 0x00000000;
252 CANx->
BTR = (uint32_t)((uint32_t)CAN_InitStruct->
CAN_Mode << 30) | \
253 ((uint32_t)CAN_InitStruct->
CAN_SJW << 24) | \
254 ((uint32_t)CAN_InitStruct->
CAN_BS1 << 16) | \
255 ((uint32_t)CAN_InitStruct->
CAN_BS2 << 20) | \
294 uint32_t filter_number_bit_pos = 0;
302 filter_number_bit_pos = ((uint32_t)1) << CAN_FilterInitStruct->
CAN_FilterNumber;
308 CAN1->FA1R &= ~(uint32_t)filter_number_bit_pos;
314 CAN1->FS1R &= ~(uint32_t)filter_number_bit_pos;
332 CAN1->FS1R |= filter_number_bit_pos;
347 CAN1->FM1R &= ~(uint32_t)filter_number_bit_pos;
352 CAN1->FM1R |= (uint32_t)filter_number_bit_pos;
359 CAN1->FFA1R &= ~(uint32_t)filter_number_bit_pos;
365 CAN1->FFA1R |= (uint32_t)filter_number_bit_pos;
371 CAN1->FA1R |= filter_number_bit_pos;
437 CAN1->FMR &= (uint32_t)0xFFFFC0F1 ;
438 CAN1->FMR |= (uint32_t)(CAN_BankNumber)<<8;
517 uint8_t transmit_mailbox = 0;
527 transmit_mailbox = 0;
531 transmit_mailbox = 1;
535 transmit_mailbox = 2;
561 TxMessage->
DLC &= (uint8_t)0x0000000F;
567 ((uint32_t)TxMessage->
Data[2] << 16) |
568 ((uint32_t)TxMessage->
Data[1] << 8) |
569 ((uint32_t)TxMessage->
Data[0]));
571 ((uint32_t)TxMessage->
Data[6] << 16) |
572 ((uint32_t)TxMessage->
Data[5] << 8) |
573 ((uint32_t)TxMessage->
Data[4]));
577 return transmit_mailbox;
597 switch (TransmitMailbox)
634 return (uint8_t) state;
745 uint8_t message_pending=0;
751 message_pending = (uint8_t)(CANx->
RF0R&(uint32_t)0x03);
755 message_pending = (uint8_t)(CANx->
RF1R&(uint32_t)0x03);
761 return message_pending;
873 return (uint8_t)sleepstatus;
904 return (uint8_t)wakeupstatus;
1013 CANx->
IER |= CAN_IT;
1018 CANx->
IER &= ~CAN_IT;
1055 if ((CANx->
ESR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1069 if ((CANx->
MSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1083 if ((CANx->
TSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1097 if ((CANx->
RF0R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1111 if ((uint32_t)(CANx->
RF1R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1157 flagtmp = CAN_FLAG & 0x000FFFFF;
1162 CANx->
RF0R = (uint32_t)(flagtmp);
1167 CANx->
RF1R = (uint32_t)(flagtmp);
1172 CANx->
TSR = (uint32_t)(flagtmp);
1177 CANx->
MSR = (uint32_t)(flagtmp);
1389 if ((CAN_Reg & It_Bit) != (uint32_t)
RESET)
1392 pendingbitstatus =
SET;
1397 pendingbitstatus =
RESET;
1399 return pendingbitstatus;
#define IS_CAN_BANKNUMBER(BANKNUMBER)
#define IS_CAN_FILTER_FIFO(FIFO)
uint8_t CAN_Init(CAN_TypeDef *CANx, CAN_InitTypeDef *CAN_InitStruct)
Initializes the CAN peripheral according to the specified parameters in the CAN_InitStruct.
uint8_t CAN_Transmit(CAN_TypeDef *CANx, CanTxMsg *TxMessage)
Initiates the transmission of a message.
void CAN_DBGFreeze(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disables the DBG Freeze for CAN.
void CAN_DeInit(CAN_TypeDef *CANx)
Deinitializes the CAN peripheral registers to their default reset values.
#define CAN_InitStatus_Failed
CAN init structure definition.
void CAN_StructInit(CAN_InitTypeDef *CAN_InitStruct)
Fills each CAN_InitStruct member with its default value.
#define IS_CAN_OPERATING_MODE(MODE)
FunctionalState CAN_FilterActivation
void CAN_ITConfig(CAN_TypeDef *CANx, uint32_t CAN_IT, FunctionalState NewState)
Enables or disables the specified CANx interrupts.
void CAN_Receive(CAN_TypeDef *CANx, uint8_t FIFONumber, CanRxMsg *RxMessage)
Receives a message.
void CAN_SlaveStartBank(uint8_t CAN_BankNumber)
Select the start bank filter for slave CAN.
uint16_t CAN_FilterIdHigh
uint8_t CAN_TransmitStatus(CAN_TypeDef *CANx, uint8_t TransmitMailbox)
Checks the transmission of a message.
void assert_param(int val)
#define CAN_OperatingMode_Normal
void CAN_CancelTransmit(CAN_TypeDef *CANx, uint8_t Mailbox)
Cancels a transmit request.
#define IS_FUNCTIONAL_STATE(STATE)
static volatile uint8_t * status
#define IS_CAN_ALL_PERIPH(PERIPH)
#define IS_CAN_GET_FLAG(FLAG)
uint8_t CAN_OperatingModeRequest(CAN_TypeDef *CANx, uint8_t CAN_OperatingMode)
Select the CAN Operation mode.
void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Forces or releases Low Speed APB (APB1) peripheral reset.
#define IS_CAN_MODE(MODE)
#define IS_CAN_CLEAR_FLAG(FLAG)
void CAN_TTComModeCmd(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disabes the CAN Time TriggerOperation communication mode.
#define IS_CAN_IDTYPE(IDTYPE)
uint8_t CAN_MessagePending(CAN_TypeDef *CANx, uint8_t FIFONumber)
Returns the number of pending messages.
void CAN_ClearITPendingBit(CAN_TypeDef *CANx, uint32_t CAN_IT)
Clears the CANx's interrupt pending bits.
static ITStatus CheckITStatus(uint32_t CAN_Reg, uint32_t It_Bit)
Checks whether the CAN interrupt has occurred or not.
#define CAN_OperatingMode_Sleep
uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef *CANx)
Returns the CANx Receive Error Counter (REC).
#define IS_CAN_STDID(STDID)
#define CAN_TxStatus_NoMailBox
#define IS_CAN_CLEAR_IT(IT)
void CAN_FilterInit(CAN_FilterInitTypeDef *CAN_FilterInitStruct)
Initializes the CAN peripheral according to the specified parameters in the CAN_FilterInitStruct.
#define IS_CAN_FILTER_NUMBER(NUMBER)
#define IS_CAN_EXTID(EXTID)
#define CAN_TxStatus_Pending
This file contains all the functions prototypes for the RCC firmware library.
#define IS_CAN_PRESCALER(PRESCALER)
void CAN_FIFORelease(CAN_TypeDef *CANx, uint8_t FIFONumber)
Releases the specified FIFO.
uint8_t CAN_Sleep(CAN_TypeDef *CANx)
Enters the low power mode.
uint8_t CAN_GetLastErrorCode(CAN_TypeDef *CANx)
Returns the CANx's last error code (LEC).
#define IS_CAN_FILTER_SCALE(SCALE)
ITStatus CAN_GetITStatus(CAN_TypeDef *CANx, uint32_t CAN_IT)
Checks whether the specified CANx interrupt has occurred or not.
#define CAN_TxStatus_Failed
uint16_t CAN_FilterFIFOAssignment
#define CAN_FilterScale_32bit
#define IS_CAN_FILTER_MODE(MODE)
#define RCC_APB1Periph_CAN2
uint8_t CAN_WakeUp(CAN_TypeDef *CANx)
Wakes the CAN up.
CAN filter init structure definition.
CAN Tx message structure definition.
uint16_t CAN_FilterMaskIdHigh
#define CAN_ModeStatus_Failed
#define CAN_WakeUp_Failed
void CAN_ClearFlag(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Clears the CAN's pending flags.
CAN_FIFOMailBox_TypeDef sFIFOMailBox[2]
#define CAN_FilterMode_IdMask
#define IS_CAN_FIFO(FIFO)
uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef *CANx)
Returns the LSB of the 9-bit CANx Transmit Error Counter(TEC).
#define CAN_OperatingMode_Initialization
#define CAN_ModeStatus_Success
uint16_t CAN_FilterMaskIdLow
#define CAN_InitStatus_Success
#define RCC_APB1Periph_CAN1
CAN_TxMailBox_TypeDef sTxMailBox[3]
This file contains all the functions prototypes for the CAN firmware library.
#define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX)
FlagStatus CAN_GetFlagStatus(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Checks whether the specified CAN flag is set or not.
CAN Rx message structure definition.
#define CAN_FilterScale_16bit