MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / CAN_Init

Function CAN_Init

bsp/loongson/ls1cdev/libraries/ls1c_can.c:83–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83unsigned char CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct)
84{
85 unsigned char InitStatus = CAN_InitStatus_Failed;
86 unsigned long wait_ack = 0x00000000;
87 unsigned char status;
88
89 status = CANx->MOD;
90 if( status == 0xFF)
91 {
92 printf("\n Probe can0 failed \r\n");
93 return CAN_InitStatus_Failed;
94 }
95
96 /* 进入复位模式 */
97 InitStatus = set_reset_mode(CANx);
98
99 if((CAN_InitStruct->CAN_Mode & CAN_Mode_SM) == CAN_Mode_SM)
100 {
101 /* 睡眠模式 1: 睡眠 0: 唤醒*/
102 CANx->MOD|= (unsigned char)CAN_Mode_SM;
103 }
104 else
105 {
106 CANx->MOD&=~ (unsigned char)CAN_Mode_SM;
107 }
108
109 if((CAN_InitStruct->CAN_Mode & CAN_Mode_LOM) == CAN_Mode_LOM)
110 {
111 /*只听模式 1:只听 0:正常 */
112 CANx->MOD|= (unsigned char)CAN_Mode_LOM;
113 }
114 else
115 {
116 CANx->MOD&=~ (unsigned char)CAN_Mode_LOM;
117 }
118
119 if((CAN_InitStruct->CAN_Mode & CAN_Mode_AFM) == CAN_Mode_AFM)
120 {
121 /*单滤波模式 1:单 0: 双*/
122 CANx->MOD |= (unsigned char)CAN_Mode_AFM;
123 }
124 else
125 {
126 CANx->MOD&=~ (unsigned char)CAN_Mode_AFM;
127 }
128
129 if((CAN_InitStruct->CAN_Mode & CAN_Mode_STM) == CAN_Mode_STM)
130 {
131 /*自检测模式 1:自检测 0:正常 */
132 CANx->MOD |= (unsigned char)CAN_Mode_STM;
133 }
134 else
135 {
136 CANx->MOD&=~ (unsigned char)CAN_Mode_STM;
137 }
138
139 /* 配置时钟频率 */
140 CANx->BTR0 = (( unsigned char )( unsigned char )CAN_InitStruct->CAN_Prescaler -1) | \

Callers 1

bxcan_initFunction · 0.50

Calls 3

set_reset_modeFunction · 0.85
set_startFunction · 0.85
printfFunction · 0.50

Tested by

no test coverage detected