mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-22 17:12:55 +08:00
689 lines
28 KiB
C
689 lines
28 KiB
C
/******************************************************************************************************************************************
|
||
* <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>: SWM320_can.c
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: SWM320<32><30>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>CANģ<4E><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* <20><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>: http://www.synwit.com.cn/e/tool/gbook/?bid=1
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:
|
||
* <20>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD>: V1.1.0 2017<31><37>10<31><30>25<32><35>
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼:
|
||
*
|
||
*
|
||
*******************************************************************************************************************************************
|
||
* @attention
|
||
*
|
||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION
|
||
* REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, SYNWIT SHALL NOT BE HELD LIABLE
|
||
* FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
|
||
* OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
|
||
* -ECTION WITH THEIR PRODUCTS.
|
||
*
|
||
* COPYRIGHT 2012 Synwit Technology
|
||
*******************************************************************************************************************************************/
|
||
#include "SWM320.h"
|
||
#include "SWM320_can.h"
|
||
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_Init()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: CAN<41>ӿڳ<D3BF>ʼ<EFBFBD><CABC>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* CAN_InitStructure * initStruct <20><><EFBFBD><EFBFBD>CAN<41>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>趨ֵ<E8B6A8>Ľṹ<C4BD><E1B9B9>
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_Init(CAN_TypeDef * CANx, CAN_InitStructure * initStruct)
|
||
{
|
||
switch((uint32_t)CANx)
|
||
{
|
||
case ((uint32_t)CAN):
|
||
SYS->CLKEN |= (0x01 << SYS_CLKEN_CAN_Pos);
|
||
break;
|
||
}
|
||
|
||
CAN_Close(CANx); //һЩ<D2BB>ؼ<EFBFBD><D8BC>Ĵ<EFBFBD><C4B4><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>CAN<41>ر<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||
|
||
CANx->CR &= ~(CAN_CR_LOM_Msk | CAN_CR_STM_Msk | CAN_CR_AFM_Msk);
|
||
CANx->CR |= (initStruct->Mode << CAN_CR_LOM_Pos) |
|
||
(initStruct->FilterMode << CAN_CR_AFM_Pos);
|
||
|
||
CANx->FILTER.AMR[3] = initStruct->FilterMask32b & 0xFF;
|
||
CANx->FILTER.AMR[2] = (initStruct->FilterMask32b >> 8) & 0xFF;
|
||
CANx->FILTER.AMR[1] = (initStruct->FilterMask32b >> 16) & 0xFF;
|
||
CANx->FILTER.AMR[0] = (initStruct->FilterMask32b >> 24) & 0xFF;
|
||
|
||
CANx->FILTER.ACR[3] = initStruct->FilterCheck32b & 0xFF;
|
||
CANx->FILTER.ACR[2] = (initStruct->FilterCheck32b >> 8) & 0xFF;
|
||
CANx->FILTER.ACR[1] = (initStruct->FilterCheck32b >> 16) & 0xFF;
|
||
CANx->FILTER.ACR[0] = (initStruct->FilterCheck32b >> 24) & 0xFF;
|
||
|
||
CANx->BT1 = (0 << CAN_BT1_SAM_Pos) |
|
||
(initStruct->CAN_BS1 << CAN_BT1_TSEG1_Pos) |
|
||
(initStruct->CAN_BS2 << CAN_BT1_TSEG2_Pos);
|
||
|
||
CANx->BT0 = (initStruct->CAN_SJW << CAN_BT0_SJW_Pos) |
|
||
((SystemCoreClock/2/initStruct->Baudrate/(1 + (initStruct->CAN_BS1 + 1) + (initStruct->CAN_BS2 + 1)) - 1) << CAN_BT0_BRP_Pos);
|
||
|
||
CANx->RXERR = 0; //ֻ<><D6BB><EFBFBD>ڸ<EFBFBD>λģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
CANx->TXERR = 0;
|
||
|
||
CANx->IE = (initStruct->RXNotEmptyIEn << CAN_IE_RXDA_Pos) |
|
||
(initStruct->RXOverflowIEn << CAN_IE_RXOV_Pos) |
|
||
(initStruct->ArbitrLostIEn << CAN_IE_ARBLOST_Pos) |
|
||
(initStruct->ErrPassiveIEn << CAN_IE_ERRPASS_Pos);
|
||
|
||
switch((uint32_t)CANx)
|
||
{
|
||
case ((uint32_t)CAN):
|
||
if(initStruct->RXNotEmptyIEn | initStruct->RXOverflowIEn | initStruct->ArbitrLostIEn | initStruct->ErrPassiveIEn)
|
||
{
|
||
NVIC_EnableIRQ(CAN_IRQn);
|
||
}
|
||
else
|
||
{
|
||
NVIC_DisableIRQ(CAN_IRQn);
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_Open()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: CAN<41>ӿڴ<D3BF><DAB4><EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_Open(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->CR &= ~(0x01 << CAN_CR_RST_Pos); //<2F>˳<EFBFBD><CBB3><EFBFBD>λģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD>빤<EFBFBD><EBB9A4>ģʽ
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_Close()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: CAN<41>ӿڹر<DAB9>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_Close(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->CR |= (0x01 << CAN_CR_RST_Pos); //<2F><><EFBFBD>븴λģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD>ܷ<EFBFBD><DCB7>ͺͽ<CDBA><CDBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_Transmit()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: CAN<41><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* uint32_t format CAN_FRAME_STD <20><>֡ CAN_FRAME_EXT <20><>չ֡
|
||
* uint32_t id <09><>ϢID
|
||
* uint8_t data[] Ҫ<><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD>
|
||
* uint32_t size Ҫ<><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݵĸ<DDB5><C4B8><EFBFBD>
|
||
* uint32_t once ֻ<><D6BB><EFBFBD><EFBFBD>һ<EFBFBD>Σ<EFBFBD><CEA3><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3>ٲö<D9B2>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD><EFBFBD>NAK<41><4B>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ط<EFBFBD>
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_Transmit(CAN_TypeDef * CANx, uint32_t format, uint32_t id, uint8_t data[], uint32_t size, uint32_t once)
|
||
{
|
||
uint32_t i;
|
||
|
||
if(format == CAN_FRAME_STD)
|
||
{
|
||
CANx->TXFRAME.INFO = (0 << CAN_INFO_FF_Pos) |
|
||
(0 << CAN_INFO_RTR_Pos) |
|
||
(size << CAN_INFO_DLC_Pos);
|
||
|
||
CANx->TXFRAME.DATA[0] = id >> 3;
|
||
CANx->TXFRAME.DATA[1] = id << 5;
|
||
|
||
for(i = 0; i < size; i++)
|
||
{
|
||
CANx->TXFRAME.DATA[i+2] = data[i];
|
||
}
|
||
}
|
||
else //if(format == CAN_FRAME_EXT)
|
||
{
|
||
CANx->TXFRAME.INFO = (1 << CAN_INFO_FF_Pos) |
|
||
(0 << CAN_INFO_RTR_Pos) |
|
||
(size << CAN_INFO_DLC_Pos);
|
||
|
||
CANx->TXFRAME.DATA[0] = id >> 21;
|
||
CANx->TXFRAME.DATA[1] = id >> 13;
|
||
CANx->TXFRAME.DATA[2] = id >> 5;
|
||
CANx->TXFRAME.DATA[3] = id << 3;
|
||
|
||
for(i = 0; i < size; i++)
|
||
{
|
||
CANx->TXFRAME.DATA[i+4] = data[i];
|
||
}
|
||
}
|
||
|
||
if(CANx->CR & CAN_CR_STM_Msk)
|
||
{
|
||
CANx->CMD = (1 << CAN_CMD_SRR_Pos);
|
||
}
|
||
else
|
||
{
|
||
if(once == 0)
|
||
{
|
||
CANx->CMD = (1 << CAN_CMD_TXREQ_Pos);
|
||
}
|
||
else
|
||
{
|
||
CANx->CMD = (1 << CAN_CMD_TXREQ_Pos) | (1 << CAN_CMD_ABTTX_Pos);
|
||
}
|
||
}
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_TransmitRequest()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: CAN<41><4E><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>̽ڵ㷢<DAB5><E3B7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* uint32_t format CAN_FRAME_STD <20><>֡ CAN_FRAME_EXT <20><>չ֡
|
||
* uint32_t id <09><>ϢID
|
||
* uint32_t once ֻ<><D6BB><EFBFBD><EFBFBD>һ<EFBFBD>Σ<EFBFBD><CEA3><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3>ٲö<D9B2>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD><EFBFBD>NAK<41><4B>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ط<EFBFBD>
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_TransmitRequest(CAN_TypeDef * CANx, uint32_t format, uint32_t id, uint32_t once)
|
||
{
|
||
if(format == CAN_FRAME_STD)
|
||
{
|
||
CANx->TXFRAME.INFO = (0 << CAN_INFO_FF_Pos) |
|
||
(1 << CAN_INFO_RTR_Pos) |
|
||
(0 << CAN_INFO_DLC_Pos);
|
||
|
||
CANx->TXFRAME.DATA[0] = id >> 3;
|
||
CANx->TXFRAME.DATA[1] = id << 5;
|
||
}
|
||
else //if(format == CAN_FRAME_EXT)
|
||
{
|
||
CANx->TXFRAME.INFO = (1 << CAN_INFO_FF_Pos) |
|
||
(1 << CAN_INFO_RTR_Pos) |
|
||
(0 << CAN_INFO_DLC_Pos);
|
||
|
||
CANx->TXFRAME.DATA[0] = id >> 21;
|
||
CANx->TXFRAME.DATA[1] = id >> 13;
|
||
CANx->TXFRAME.DATA[2] = id >> 5;
|
||
CANx->TXFRAME.DATA[3] = id << 3;
|
||
}
|
||
|
||
if(once == 0)
|
||
{
|
||
CANx->CMD = (1 << CAN_CMD_TXREQ_Pos);
|
||
}
|
||
else
|
||
{
|
||
CANx->CMD = (1 << CAN_CMD_TXREQ_Pos) | (1 << CAN_CMD_ABTTX_Pos);
|
||
}
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_Receive()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: CAN<41><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* CAN_RXMessage *msg <09><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>洢<EFBFBD>ڴ˽ṹ<CBBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_Receive(CAN_TypeDef * CANx, CAN_RXMessage *msg)
|
||
{
|
||
uint32_t i;
|
||
msg->format = (CANx->RXFRAME.INFO & CAN_INFO_FF_Msk) >> CAN_INFO_FF_Pos;
|
||
|
||
msg->remote = (CANx->RXFRAME.INFO & CAN_INFO_RTR_Msk) >> CAN_INFO_RTR_Pos;
|
||
msg->size = (CANx->RXFRAME.INFO & CAN_INFO_DLC_Msk) >> CAN_INFO_DLC_Pos;
|
||
|
||
if(msg->format == CAN_FRAME_STD)
|
||
{
|
||
msg->id = (CANx->RXFRAME.DATA[0] << 3) | (CANx->RXFRAME.DATA[1] >> 5);
|
||
|
||
for(i = 0; i < msg->size; i++)
|
||
{
|
||
msg->data[i] = CANx->RXFRAME.DATA[i+2];
|
||
}
|
||
}
|
||
else //if(msg->format == CAN_FRAME_EXT)
|
||
{
|
||
msg->id = (CANx->RXFRAME.DATA[0] << 21) | (CANx->RXFRAME.DATA[1] << 13) | (CANx->RXFRAME.DATA[2] << 5) | (CANx->RXFRAME.DATA[3] >> 3);
|
||
|
||
for(i = 0; i < msg->size; i++)
|
||
{
|
||
msg->data[i] = CANx->RXFRAME.DATA[i+4];
|
||
}
|
||
}
|
||
|
||
CANx->CMD = (1 << CAN_CMD_RRB_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_TXComplete()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD> 0 <20><>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD>ͱ<EFBFBD>AbortҲ<74>ᴥ<EFBFBD><E1B4A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ᴥ<EFBFBD><E1B4A5><EFBFBD><EFBFBD><EFBFBD>ͳɹ<CDB3>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_TXComplete(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->SR & CAN_SR_TXBR_Msk) ? 1 : 0;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_TXSuccess()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ɹ<EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20><><EFBFBD>ͳɹ<CDB3> 0 <20><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_TXSuccess(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->SR & CAN_SR_TXOK_Msk) ? 1 : 0;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_AbortTransmit()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD>ڽ<EFBFBD><DABD>еķ<D0B5><C4B7><EFBFBD><EFBFBD><EFBFBD><DEB7><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>ִ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ط<EFBFBD>
|
||
******************************************************************************************************************************************/
|
||
void CAN_AbortTransmit(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->CMD = (1 << CAN_CMD_ABTTX_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_TXBufferReady()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: TX Buffer<65>Ƿ<EFBFBD><EFBFBD><D7BC><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>Ϣ
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20><><EFBFBD><D7BC><EFBFBD><EFBFBD> 0 δ<CEB4><D7BC><EFBFBD><EFBFBD>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_TXBufferReady(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->SR & CAN_SR_TXBR_Msk) ? 1 : 0;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_RXDataAvailable()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: RX FIFO<46><4F><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿɶ<DDBF><C9B6><EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20><><EFBFBD><EFBFBD><EFBFBD>ݿɶ<DDBF><C9B6><EFBFBD> 0 û<><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_RXDataAvailable(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->SR & CAN_SR_RXDA_Msk) ? 1 : 0;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_SetBaudrate()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* uint32_t baudrate <09><><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* uint32_t CAN_BS1 CAN_BS1_1tq<74><71>CAN_BS1_2tq<74><71>... ... <20><>CAN_BS1_16tq
|
||
* uint32_t CAN_BS2 CAN_BS2_1tq<74><71>CAN_BS2_2tq<74><71>... ... <20><>CAN_BS2_8tq
|
||
* uint32_t CAN_SJW CAN_SJW_1tq<74><71>CAN_SJW_2tq<74><71>CAN_SJW_3tq<74><71>CAN_SJW_4tq
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>Ҫ<EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD>CAN_Close()<29>ر<EFBFBD>CANģ<4E><C4A3>
|
||
******************************************************************************************************************************************/
|
||
void CAN_SetBaudrate(CAN_TypeDef * CANx, uint32_t baudrate, uint32_t CAN_BS1, uint32_t CAN_BS2, uint32_t CAN_SJW)
|
||
{
|
||
CANx->BT1 = (0 << CAN_BT1_SAM_Pos) |
|
||
(CAN_BS1 << CAN_BT1_TSEG1_Pos) |
|
||
(CAN_BS2 << CAN_BT1_TSEG2_Pos);
|
||
|
||
CANx->BT0 = (CAN_SJW << CAN_BT0_SJW_Pos) |
|
||
((SystemCoreClock/2/baudrate/(1 + (CAN_BS1 + 1) + (CAN_BS2 + 1)) - 1) << CAN_BT0_BRP_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_SetFilter32b()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>32λ<32>˲<EFBFBD><CBB2><EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* uint32_t check <09><>maskһ<6B><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˽<EFBFBD><CBBD>յ<EFBFBD><D5B5><EFBFBD>Message<67>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>Ҫ<EFBFBD>ģ<EFBFBD>check & (~mask) == ID & (~mask)<29><>Messageͨ<65><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* uint32_t mask
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>Ҫ<EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD>CAN_Close()<29>ر<EFBFBD>CANģ<4E><C4A3>
|
||
******************************************************************************************************************************************/
|
||
void CAN_SetFilter32b(CAN_TypeDef * CANx, uint32_t check, uint32_t mask)
|
||
{
|
||
CANx->CR &= ~CAN_CR_AFM_Msk;
|
||
CANx->CR |= (CAN_FILTER_32b << CAN_CR_AFM_Pos);
|
||
|
||
CANx->FILTER.AMR[3] = mask & 0xFF;
|
||
CANx->FILTER.AMR[2] = (mask >> 8) & 0xFF;
|
||
CANx->FILTER.AMR[1] = (mask >> 16) & 0xFF;
|
||
CANx->FILTER.AMR[0] = (mask >> 24) & 0xFF;
|
||
|
||
CANx->FILTER.ACR[3] = check & 0xFF;
|
||
CANx->FILTER.ACR[2] = (check >> 8) & 0xFF;
|
||
CANx->FILTER.ACR[1] = (check >> 16) & 0xFF;
|
||
CANx->FILTER.ACR[0] = (check >> 24) & 0xFF;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_SetFilter16b()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD>˲<EFBFBD><CBB2><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32>16λ<36>˲<EFBFBD><CBB2><EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* uint16_t check1 <09><>maskһ<6B><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˽<EFBFBD><CBBD>յ<EFBFBD><D5B5><EFBFBD>Message<67>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>Ҫ<EFBFBD>ģ<EFBFBD>check & (~mask) == ID & (~mask)<29><>Messageͨ<65><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
* uint16_t mask1
|
||
* uint16_t check2
|
||
* uint16_t mask2
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>Ҫ<EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD>CAN_Close()<29>ر<EFBFBD>CANģ<4E><C4A3>
|
||
******************************************************************************************************************************************/
|
||
void CAN_SetFilter16b(CAN_TypeDef * CANx, uint16_t check1, uint16_t mask1, uint16_t check2, uint16_t mask2)
|
||
{
|
||
CANx->CR &= ~CAN_CR_AFM_Msk;
|
||
CANx->CR |= (CAN_FILTER_16b << CAN_CR_AFM_Pos);
|
||
|
||
CANx->FILTER.AMR[3] = mask1 & 0xFF;
|
||
CANx->FILTER.AMR[2] = (mask1 >> 8) & 0xFF;
|
||
CANx->FILTER.AMR[1] = mask2 & 0xFF;
|
||
CANx->FILTER.AMR[0] = (mask2 >> 8) & 0xFF;
|
||
|
||
CANx->FILTER.ACR[3] = check1 & 0xFF;
|
||
CANx->FILTER.ACR[2] = (check1 >> 8) & 0xFF;
|
||
CANx->FILTER.ACR[1] = check2 & 0xFF;
|
||
CANx->FILTER.ACR[0] = (check2 >> 8) & 0xFF;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTRXNotEmptyEn()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><>RX FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ǿգ<C7BF><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTRXNotEmptyEn(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE |= (1 << CAN_IE_RXDA_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTRXNotEmptyDis()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><>RX FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ǿգ<C7BF><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϽ<D0B6>ֹ
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTRXNotEmptyDis(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE &= ~(1 << CAN_IE_RXDA_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTRXNotEmptyStat()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: RX FIFO<46>ǿ<EFBFBD><C7BF>ж<EFBFBD><D0B6>Ƿ<C7B7>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20>Ѵ<EFBFBD><D1B4><EFBFBD> 0 δ<><CEB4><EFBFBD><EFBFBD>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_INTRXNotEmptyStat(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->IF & CAN_IF_RXDA_Msk) ? 1 : 0;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTTXBufEmptyEn()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><>TX Buffer<65><72>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTTXBufEmptyEn(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE |= (1 << CAN_IE_TXBR_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTTXBufEmptyDis()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><>TX Buffer<65><72>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>жϽ<D0B6>ֹ
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTTXBufEmptyDis(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE &= ~(1 << CAN_IE_TXBR_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTTXBufEmptyStat()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: TX Buffer<65><72><EFBFBD>ж<EFBFBD><D0B6>Ƿ<C7B7>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20>Ѵ<EFBFBD><D1B4><EFBFBD> 0 δ<><CEB4><EFBFBD><EFBFBD>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_INTTXBufEmptyStat(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->IF & CAN_IF_TXBR_Msk) ? 1 : 0;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTErrWarningEn()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: TXERR/RXERR<52><52><EFBFBD><EFBFBD>ֵ<EFBFBD>ﵽError Warning Limitʱ<74><CAB1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTErrWarningEn(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE |= (1 << CAN_IE_ERRWARN_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTErrWarningDis()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: TXERR/RXERR<52><52><EFBFBD><EFBFBD>ֵ<EFBFBD>ﵽError Warning Limitʱ<74><CAB1><EFBFBD><EFBFBD><EFBFBD>жϽ<D0B6>ֹ
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTErrWarningDis(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE &= ~(1 << CAN_IE_ERRWARN_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTErrWarningStat()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: TXERR/RXERR<52><52><EFBFBD><EFBFBD>ֵ<EFBFBD>ﵽError Warning Limit<69>ж<EFBFBD><D0B6>Ƿ<C7B7>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20>Ѵ<EFBFBD><D1B4><EFBFBD> 0 δ<><CEB4><EFBFBD><EFBFBD>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_INTErrWarningStat(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->IF & CAN_IF_ERRWARN_Msk) ? 1 : 0;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTRXOverflowEn()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: RX FIFO <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTRXOverflowEn(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE |= (1 << CAN_IE_RXOV_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTRXOverflowDis()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: RX FIFO <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>жϽ<D0B6>ֹ
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTRXOverflowDis(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE &= ~(1 << CAN_IE_RXOV_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTRXOverflowStat()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: RX FIFO <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>Ƿ<C7B7>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20>Ѵ<EFBFBD><D1B4><EFBFBD> 0 δ<><CEB4><EFBFBD><EFBFBD>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_INTRXOverflowStat(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->IF & CAN_IF_RXOV_Msk) ? 1 : 0;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTRXOverflowClear()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: RX FIFO <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTRXOverflowClear(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->CMD = (1 << CAN_CMD_CLROV_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTWakeupEn()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTWakeupEn(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE |= (1 << CAN_IE_WKUP_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTWakeupDis()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϽ<D0B6>ֹ
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTWakeupDis(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE &= ~(1 << CAN_IE_WKUP_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTWakeupStat()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ж<EFBFBD><D0B6>Ƿ<C7B7>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20>Ѵ<EFBFBD><D1B4><EFBFBD> 0 δ<><CEB4><EFBFBD><EFBFBD>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_INTWakeupStat(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->IF & CAN_IF_WKUP_Msk) ? 1 : 0;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTErrPassiveEn()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: TXERR/RXERR<52><52><EFBFBD><EFBFBD>ֵ<EFBFBD>ﵽ127ʱ<37>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTErrPassiveEn(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE |= (1 << CAN_IE_ERRPASS_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTErrPassiveDis()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: TXERR/RXERR<52><52><EFBFBD><EFBFBD>ֵ<EFBFBD>ﵽ127ʱ<37>жϽ<D0B6>ֹ
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTErrPassiveDis(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE &= ~(1 << CAN_IE_ERRPASS_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTErrPassiveStat()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: TXERR/RXERR<52><52><EFBFBD><EFBFBD>ֵ<EFBFBD>ﵽ127<32>ж<EFBFBD><D0B6>Ƿ<C7B7>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20>Ѵ<EFBFBD><D1B4><EFBFBD> 0 δ<><CEB4><EFBFBD><EFBFBD>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_INTErrPassiveStat(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->IF & CAN_IF_ERRPASS_Msk) ? 1 : 0;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTArbitrLostEn()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09>ٲ<EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTArbitrLostEn(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE |= (1 << CAN_IE_ARBLOST_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTArbitrLostDis()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09>ٲ<EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD>жϽ<D0B6>ֹ
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTArbitrLostDis(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE &= ~(1 << CAN_IE_ARBLOST_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTArbitrLostStat()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09>ٲ<EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD>ж<EFBFBD><D0B6>Ƿ<C7B7>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20>Ѵ<EFBFBD><D1B4><EFBFBD> 0 δ<><CEB4><EFBFBD><EFBFBD>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_INTArbitrLostStat(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->IF & CAN_IF_ARBLOST_Msk) ? 1 : 0;
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTBusErrorEn()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD><EFBFBD>ж<EFBFBD>ʹ<EFBFBD><CAB9>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTBusErrorEn(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE |= (1 << CAN_IE_BUSERR_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTBusErrorDis()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD><EFBFBD>жϽ<D0B6>ֹ
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: <20><>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
void CAN_INTBusErrorDis(CAN_TypeDef * CANx)
|
||
{
|
||
CANx->IE &= ~(1 << CAN_IE_BUSERR_Pos);
|
||
}
|
||
|
||
/******************************************************************************************************************************************
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: CAN_INTBusErrorStat()
|
||
* <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <09><><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>Ƿ<C7B7>
|
||
* <20><> <20><>: CAN_TypeDef * CANx ָ<><D6B8>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>CAN<41>ӿڣ<D3BF><DAA3><EFBFBD>Чֵ<D0A7><D6B5><EFBFBD><EFBFBD>CAN
|
||
* <20><> <20><>: uint32_t 1 <20>Ѵ<EFBFBD><D1B4><EFBFBD> 0 δ<><CEB4><EFBFBD><EFBFBD>
|
||
* ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><>
|
||
******************************************************************************************************************************************/
|
||
uint32_t CAN_INTBusErrorStat(CAN_TypeDef * CANx)
|
||
{
|
||
return (CANx->IF & CAN_IF_BUSERR_Msk) ? 1 : 0;
|
||
}
|