@@ -29,8 +29,7 @@ static CAN_HandleTypeDef CanHandle;
29
29
static uint32_t can_irq_ids [CAN_NUM ] = {0 };
30
30
static can_irq_handler irq_handler ;
31
31
32
- void can_init (can_t * obj , PinName rd , PinName td )
33
- {
32
+ void can_init (can_t * obj , PinName rd , PinName td ) {
34
33
CANName can_rd = (CANName )pinmap_peripheral (rd , PinMap_CAN_RD );
35
34
CANName can_td = (CANName )pinmap_peripheral (td , PinMap_CAN_TD );
36
35
@@ -86,23 +85,20 @@ void can_init(can_t *obj, PinName rd, PinName td)
86
85
can_filter (obj , 0 , 0 , CANStandard , filter_number );
87
86
}
88
87
89
- void can_irq_init (can_t * obj , can_irq_handler handler , uint32_t id )
90
- {
88
+ void can_irq_init (can_t * obj , can_irq_handler handler , uint32_t id ) {
91
89
irq_handler = handler ;
92
90
can_irq_ids [obj -> index ] = id ;
93
91
}
94
92
95
- void can_irq_free (can_t * obj )
96
- {
93
+ void can_irq_free (can_t * obj ) {
97
94
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
98
95
99
96
can -> IER &= ~(CAN_IT_FMP0 | CAN_IT_FMP1 | CAN_IT_TME | \
100
97
CAN_IT_ERR | CAN_IT_EPV | CAN_IT_BOF );
101
98
can_irq_ids [obj -> can ] = 0 ;
102
99
}
103
100
104
- void can_free (can_t * obj )
105
- {
101
+ void can_free (can_t * obj ) {
106
102
// Reset CAN and disable clock
107
103
if (obj -> can == CAN_1 ) {
108
104
__HAL_RCC_CAN1_FORCE_RESET ();
@@ -148,8 +144,7 @@ static const int timing_pts[23][2] = {
148
144
{0xF , 0x7 }, // 24, 67%
149
145
};
150
146
151
- static unsigned int can_speed (unsigned int pclk , unsigned int cclk , unsigned char psjw )
152
- {
147
+ static unsigned int can_speed (unsigned int pclk , unsigned int cclk , unsigned char psjw ) {
153
148
uint32_t btr ;
154
149
uint16_t brp = 0 ;
155
150
uint32_t calcbit ;
@@ -184,8 +179,7 @@ static unsigned int can_speed(unsigned int pclk, unsigned int cclk, unsigned cha
184
179
185
180
}
186
181
187
- int can_frequency (can_t * obj , int f )
188
- {
182
+ int can_frequency (can_t * obj , int f ) {
189
183
int pclk = HAL_RCC_GetPCLK1Freq ();
190
184
int btr = can_speed (pclk , (unsigned int )f , 1 );
191
185
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
@@ -204,8 +198,7 @@ int can_frequency(can_t *obj, int f)
204
198
}
205
199
}
206
200
207
- int can_write (can_t * obj , CAN_Message msg , int cc )
208
- {
201
+ int can_write (can_t * obj , CAN_Message msg , int cc ) {
209
202
uint32_t transmitmailbox = 5 ;
210
203
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
211
204
@@ -248,8 +241,7 @@ int can_write(can_t *obj, CAN_Message msg, int cc)
248
241
return 1 ;
249
242
}
250
243
251
- int can_read (can_t * obj , CAN_Message * msg , int handle )
252
- {
244
+ int can_read (can_t * obj , CAN_Message * msg , int handle ) {
253
245
//handle is the FIFO number
254
246
255
247
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
@@ -295,27 +287,23 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
295
287
return 1 ;
296
288
}
297
289
298
- void can_reset (can_t * obj )
299
- {
290
+ void can_reset (can_t * obj ) {
300
291
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
301
292
can -> MCR |= CAN_MCR_RESET ;
302
293
can -> ESR = 0x0 ;
303
294
}
304
295
305
- unsigned char can_rderror (can_t * obj )
306
- {
296
+ unsigned char can_rderror (can_t * obj ) {
307
297
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
308
298
return (can -> ESR >> 24 ) & 0xFF ;
309
299
}
310
300
311
- unsigned char can_tderror (can_t * obj )
312
- {
301
+ unsigned char can_tderror (can_t * obj ) {
313
302
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
314
303
return (can -> ESR >> 16 ) & 0xFF ;
315
304
}
316
305
317
- void can_monitor (can_t * obj , int silent )
318
- {
306
+ void can_monitor (can_t * obj , int silent ) {
319
307
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
320
308
321
309
can -> MCR |= CAN_MCR_INRQ ;
@@ -333,8 +321,7 @@ void can_monitor(can_t *obj, int silent)
333
321
}
334
322
}
335
323
336
- int can_mode (can_t * obj , CanMode mode )
337
- {
324
+ int can_mode (can_t * obj , CanMode mode ) {
338
325
int success = 0 ;
339
326
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
340
327
@@ -374,8 +361,7 @@ int can_mode(can_t *obj, CanMode mode)
374
361
return success ;
375
362
}
376
363
377
- int can_filter (can_t * obj , uint32_t id , uint32_t mask , CANFormat format , int32_t handle )
378
- {
364
+ int can_filter (can_t * obj , uint32_t id , uint32_t mask , CANFormat format , int32_t handle ) {
379
365
int retval = 0 ;
380
366
381
367
// filter for CANAny format cannot be configured for STM32
@@ -408,8 +394,7 @@ int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t
408
394
return retval ;
409
395
}
410
396
411
- static void can_irq (CANName name , int id )
412
- {
397
+ static void can_irq (CANName name , int id ) {
413
398
uint32_t tmp1 = 0 , tmp2 = 0 , tmp3 = 0 ;
414
399
CanHandle .Instance = (CAN_TypeDef * )name ;
415
400
@@ -496,8 +481,7 @@ void CAN2_SCE_IRQHandler(void) {
496
481
#endif // defined(CAN2_BASE) && (CAN_NUM == 2)
497
482
#endif // else
498
483
499
- void can_irq_set (can_t * obj , CanIrqType type , uint32_t enable )
500
- {
484
+ void can_irq_set (can_t * obj , CanIrqType type , uint32_t enable ) {
501
485
502
486
CAN_TypeDef * can = (CAN_TypeDef * )(obj -> can );
503
487
IRQn_Type irq_n = (IRQn_Type )0 ;
@@ -583,4 +567,3 @@ void can_irq_set(can_t *obj, CanIrqType type, uint32_t enable)
583
567
}
584
568
585
569
#endif // DEVICE_CAN
586
-
0 commit comments